Projects Blog Tools Music Contact
← All Posts
Productivity June 3, 2026

Write Code That's Easy to Delete, Not Easy to Extend

By: Evgeny Padezhnov

Illustration for: Write Code That's Easy to Delete, Not Easy to Extend

Most codebases do not collapse under bad code. They collapse under code nobody dares to remove.

Developers spend years learning to write code. Almost no time goes into learning how to remove it. The result: bloated systems where every module is load-bearing, every function has invisible dependents, and every refactor feels like defusing a bomb. Writing code that is easy to delete flips the default. Instead of building for permanence, build for safe removal.

Why Deletability Beats Reusability

The software industry obsesses over reusability. Write once, use everywhere. In practice, reusable code creates hidden coupling. A shared utility used by twelve services cannot be changed without checking all twelve. It cannot be deleted at all.

Deletable code solves a different problem. It asks: when requirements change — and they will — can this piece be removed without breaking everything else? The answer depends on boundaries, not cleverness.

Key point: code that is easy to delete is automatically easy to replace. The reverse is not true. Code that is easy to extend often becomes impossible to remove.

Consider a payment processing module. A "reusable" version abstracts over Stripe, PayPal, and a legacy gateway. A "deletable" version wraps each gateway behind its own adapter with a clean interface. When the legacy gateway shuts down, the deletable version loses one file. The reusable version requires surgery on the shared abstraction.

Modular Design as a Deletion Strategy

Modular code design means breaking software into smaller, manageable pieces — each handling a specific task. As described in GeeksforGeeks' modular programming guide, modular programming emphasizes breaking large programs into small problems to increase maintainability and readability.

But modularity alone is not enough. Two principles determine whether a module can actually be deleted safely.

High Cohesion

A module should have a clear and focused purpose. One reason to exist. One reason to change. The Single Responsibility Principle states that each module should have only one reason to change. When a module does one thing, removing it has one consequence. When it does five things, removing it has five consequences — most of them surprising.

Low Coupling

Modules should be independent of each other. In practice, low coupling means module A does not reach into module B's internals. They communicate through interfaces, events, or dependency injection. Frameworks like Spring, Dagger, and Autofac exist specifically to manage these boundaries.

Common mistake: treating "modular" as "lots of small files." Forty tightly coupled files are worse than four well-isolated modules. File count is not modularity. Independence is.

A practical test: can a developer delete a module and have the compiler (or test suite) tell them exactly what broke? If the breakage is confined to explicit import statements and interface bindings, the module is deletable. If the breakage cascades through shared state, global variables, or implicit contracts, it is not.

Feature Flags and the Deletion Pipeline

Feature flags provide a mechanism to modify software functionality without requiring redeployment. According to CloudBees, there are four general categories: release toggles, experiment toggles, ops toggles, and permissioning toggles.

Each category has a different expected lifespan. Experiment toggles for A/B testing might live for weeks. Ops toggles for infrastructure migration might live for months. The problem starts when none of them get removed.

The main risk: flag debt. An overabundance of feature flags causes cognitive overload, which translates into further technical debt. Every flag is a branch in the code. Ten flags mean up to 1024 possible states. Most of those states are never tested.

The Feature Flag Lifecycle

CloudBees defines a feature flag lifecycle as the stages a toggle goes through: creation, testing, deployment, activation, and retirement. That last stage — retirement — is where most teams fail.

As noted by Unleash, the result of poor lifecycle management is duplicate feature flags, decaying context for what flags do and why, and flag sprawl. Peter Hilton observes that there are currently no tools specifically for feature retirement. Executing feature removal requires using most of the lifecycle tools again, in reverse.

Key point: every feature flag should have an expiration date at creation time. No exceptions. A flag without a retirement plan is a branch that will never be merged and never be deleted. Treat unretired flags as bugs.

Try it: add a createdAt and expiresAt field to every feature flag. Run a weekly report that lists flags past their expiration. Review and remove them. This single practice eliminates more technical debt than most refactoring sprints.

Writing Functions That Are Safe to Remove

What does a well-designed, easy-to-delete function actually look like? Three properties matter.

1. Explicit Dependencies

Every input comes through parameters. No globals. No ambient state. No reaching into process.env halfway through a calculation. When a function declares its dependencies, a developer can trace what happens when it disappears.

# Hard to delete — hidden dependency on global config
def calculate_price(item):
    tax_rate = config.get("tax_rate")
    return item.price * (1 + tax_rate)

# Easy to delete — all dependencies are visible
def calculate_price(item, tax_rate):
    return item.price * (1 + tax_rate)

The second version can be removed by searching for calculate_price( in the codebase. The first version might break code that never calls it directly but relies on the same config object.

2. No Side Effects Beyond Its Scope

A function that writes to a database, sends an email, and returns a value is three functions pretending to be one. When requirements change and the email is no longer needed, removing the email logic means editing the function, not deleting it. When each side effect is its own unit, removal is clean.

// Hard to delete — mixed concerns
async function processOrder(order) {
  await db.save(order);
  await emailService.sendConfirmation(order);
  await analytics.track('order_placed', order);
  return order;
}

// Easy to delete — orchestration is separate from action
async function processOrder(order, steps) {
  for (const step of steps) {
    await step(order);
  }
  return order;
}

The second version lets developers add or remove steps without touching processOrder at all. When analytics tracking gets replaced by a different system, one array entry changes.

3. Tests That Describe Behavior, Not Implementation

Tests coupled to internal implementation make deletion terrifying. If tests verify that a function calls a specific private method in a specific order, removing that private method breaks tests even when behavior is unchanged.

Good tests describe what a module does. Not how. When a module is deleted, its tests should be deleted with it — a clean removal, not a chain reaction.

The Strangler Fig Pattern

Large legacy systems cannot be deleted all at once. The strangler fig pattern offers a practical approach: build new functionality alongside the old, route traffic gradually to the new system, and remove the old one when it carries zero load.

Tested in production, this pattern works best when the old and new systems share an interface boundary — usually an API gateway or a reverse proxy. The key constraint: the new system must never depend on the old system's internals. If it does, the old system cannot be removed without breaking the new one.

Client → API Gateway → New Service (90% traffic)
                     → Legacy Service (10% traffic)

When the legacy service handles zero requests for a sustained period, it is safe to delete. Not before. Traffic metrics, not developer confidence, determine when code is ready for removal.

Dependency Management for Deletability

Every external dependency is code that someone else wrote and that the team now owns. The question is not "should there be dependencies" but "how expensive is it to remove one?"

Wrap External Libraries

Never let an external library's API spread across the codebase. Wrap it in a thin adapter. When the library is replaced or removed, one file changes instead of forty.

// Don't do this — library API everywhere
import dayjs from 'dayjs';
// ... used in 47 files

// Do this — one wrapper, used everywhere
// src/lib/dates.ts
import dayjs from 'dayjs';

export function formatDate(date: Date, pattern: string): string {
  return dayjs(date).format(pattern);
}

export function addDays(date: Date, days: number): Date {
  return dayjs(date).add(days, 'day').toDate();
}

Replacing dayjs with date-fns or a native Intl solution now requires editing one file.

Pin and Audit

Unpinned dependencies update silently and break builds months later. Pinning versions and running npm audit before deployment catches problems early. In plain terms: treat dependencies like tenants. Know who they are, what they do, and have a plan for when they leave.

Deprecation as a First-Class Practice

Microsoft's feature lifecycle documentation defines deprecation as "the stage of the product lifecycle when a feature or functionality is no longer in active development and may be removed in future releases." The critical detail: deprecation is not removal. It is a signal that removal is coming.

According to LaunchNotes, feature lifecycle analysis supports long-term product health by preventing feature bloat — where outdated or underperforming features drain resources without adding value.

Every team needs a deprecation process. At minimum:

  1. Mark — annotate the code as deprecated with a date and a reason.
  2. Measure — track usage. Zero usage means safe deletion.
  3. Communicate — notify dependents. Internal teams or external API consumers.
  4. Remove — delete the code, the tests, the documentation, and the feature flag.

Common mistake: marking code as deprecated and never removing it. A @deprecated annotation without a removal date is decoration, not deprecation.

What Deletable Architecture Looks Like

Deletable architecture shares several traits across languages and frameworks:

If it works — it is correct. No architecture style is inherently right. Microservices, monoliths, modular monoliths — any of them can produce deletable code. The structure matters less than the discipline of maintaining clean boundaries.

What to Try Right Now

Pick one module in the current codebase. Ask: "If requirements changed tomorrow and this module had to be removed, what would break?" Trace the dependencies. Count the files that import it. Check for shared state. If the answer is "too much would break" — that module is the highest-priority refactoring target. Not because the code is bad. Because the code is permanent, and permanence is the real debt.

Try it: run a dependency graph tool (madge for JavaScript, pydeps for Python, go mod graph for Go) and look for modules with the most inbound edges. Those are the hardest to delete. Start wrapping their interfaces today.

Frequently Asked Questions

How do I balance writing code that is easy to extend with making it easy to delete?

Favor deletion over extension. Code that is easy to delete can always be replaced with a better version. Code that is easy to extend accumulates layers until no one understands the original intent. Build small, isolated modules. Extend by adding new modules, not by modifying existing ones.

What is the best way to structure dependencies so they are easy to swap or remove later?

Wrap every external dependency in a thin adapter. The adapter exposes only the functions the codebase actually uses. When the dependency changes or gets removed, only the adapter file needs editing. Pin dependency versions and audit regularly.

How does the "easy to delete" philosophy help prevent technical debt accumulation?

Technical debt grows when code cannot be safely removed. Feature flags without expiration dates, deprecated modules without removal plans, and tightly coupled components all create debt that compounds over time. Deletable code makes cleanup a routine operation instead of a risky project.

What does a well-designed, easy-to-delete function or module actually look like in practice?

It takes all inputs through parameters. It produces outputs without hidden side effects. It communicates with other modules through explicit interfaces. Its tests describe what it does, not how. When removed, exactly one import statement breaks per consumer — and the compiler or test suite catches every one.

Information is accurate as of the publication date. Terms, prices, and regulations may change — verify with relevant professionals.

✦ Squeeze AI
  1. Reusable abstractions create hidden coupling that makes code impossible to remove; deletable code solves this by isolating each piece behind clean interfaces, so removing one part has one consequence, not a cascade.
  2. True modularity is about independence, not file count — forty tightly coupled small files are worse than four well-isolated modules, and the real test is whether you can delete a module and have the compiler or test suite catch every breakage immediately.

Powered by B1KEY