DEV Community

Cover image for Write Code That's Easy to Delete: The Art of Impermanent Software
Adam - The Developer
Adam - The Developer

Posted on

Write Code That's Easy to Delete: The Art of Impermanent Software

Designing for reversibility via modularity

We obsess over making code last. Maybe we should obsess over making it leave gracefully.


There's a quote that's been living rent-free in my head for years:

"Write code that is easy to delete, not easy to extend."
— Tef, programming is terrible

The first time I read it, I pushed back. Isn't the whole point to write code that survives? That scales? That you can build on top of?

Then I spent a weekend trying to rip out a logging library from a three-year-old codebase. It had quietly spread into 40 files. Removing it felt like surgery on a patient who had grown bones around a sponge.


The Lie We Tell Ourselves

When we write code, we tell ourselves a flattering story: this will be here in five years, so I should make it robust, reusable, and extensible.

But the data doesn't support this story. Most features get changed within months. Many get cut entirely. The average production codebase has entire directories that haven't been touched in years — not because they're perfect, but because everyone is too afraid to delete them.

We write code as if it's load-bearing. Usually, it isn't.

The irony is that the more we try to make code "permanent" — wrapping it in abstractions, coupling it into shared utilities, weaving it through the system, the harder it becomes to change. We've traded adaptability for the illusion of durability.


What "Easy to Delete" Actually Means

It doesn't mean write throwaway code. It doesn't mean skip tests or ignore structure.

It means: design for reversibility.

When you write a feature, ask yourself: if this needed to go away tomorrow, what would that look like?

If the answer is "a 400-line PR touching 20 files," something went wrong at the design stage — not the deletion stage.

Easy-to-delete code tends to share a few traits:

1. It lives in one place

Duplication gets a bad reputation. The DRY principle is good advice, but taken to its extreme, it creates code that's deeply entangled. When the same function is reused in eight different contexts, you can't change it for one context without worrying about all the others.

Sometimes, a little duplication is the price of independence. Two modules that both have a formatDate function can each evolve or disappear without consequences.

2. It has a clear boundary

The hardest code to delete is the code that has leaked everywhere. The database client that got imported into UI components. The config object that got passed twelve layers deep. The utility function that became load-bearing infrastructure.

Boundaries are what make deletion safe. An isolated module, a clean interface, a service behind a well-defined API... these are things you can remove, replace, or rewrite without holding or thinking through your breath.

3. It doesn't know too much

Code that's easy to delete tends to be ignorant but in the best way. It doesn't know about the rest of the system. It takes inputs, does its job, returns outputs. It doesn't reach out and grab global state. It doesn't mutate things it didn't create.

Ignorant code is also testable code, which is no coincidence ( I actually didn't wanna add this part for some personal reasons )

4. It's hidden behind a seam

Feature flags. Adapter layers. Interface abstractions. These aren't just engineering formalism — they're deletion handles. A feature behind a flag can be switched off in seconds. Code behind an interface can be swapped without the callers noticing.

The strangler fig pattern exists precisely for this reason: wrap the old thing, build the new thing alongside it, then delete the old thing once it's isolated. The seam is what makes that possible.


A Different Way to Think About Abstraction

We often reach for abstraction to avoid repetition. But the best reason to abstract something is to isolate it or to give it a name and a box so that you can change or remove it without touching everything else.

Think about logging. You could scatter console.log calls everywhere. That's easy to write and immediately painful to change. Or you could route all logging through a single logger module. Now if you want to swap logging libraries, or add context, or silence it entirely — you only touch one file. ONE.

The abstraction isn't there because logging is complex. It's there because logging is a thing that might change or disappear, and you want that to be painless.

Abstract at the seams, not in the middle.


Deletability as a Code Review Lens

Here's something I've started doing in code review: asking not just "does this work?" but "what would it take to remove this?"

It reframes things in a useful way.

A PR that adds a new feature and touches 15 files is a warning sign — not necessarily because it's wrong, but because it's announcing a high cost of future change. A PR that adds the same feature through a single, well-bounded module is leaving a cleaner footprint.

You can extend this to architecture decisions. Before adding a new dependency, ask: "what does removing this look like in two years?" Some dependencies are fine because they're small, stable, or isolated. Others are like introducing an invasive species. They grow into everything and become impossible to root out.


Impermanence Is Not Defeatism

There's a Zen concept sometimes translated as impermanence — the idea that things arise, exist for a time, and pass away. This isn't pessimism. It's just an accurate description of how things work.

Software is the same. Features come and go. Products pivot. Requirements change. The code you're writing today will be partially or wholly replaced. That's not failure — that's how living software works.

Writing for impermanence means accepting this, and designing accordingly. It means your goal isn't to write code that can never be removed. It's to write code whose removal is cheap.

The engineers who built systems that are still running 30 years later didn't achieve that by making the code impossible to touch. They achieved it by writing code that was easy to reason about, easy to isolate, and when the time came, it's easy to replace piece by piece.


In Practice: A Checklist

Before you commit something, it's worth a quick gut-check:

  • Could I delete this feature with a single PR? If not, why not?
  • How many files does this touch? More isn't always worse, but it should feel intentional.
  • Is this module aware of things it shouldn't be? Imports, globals, side effects.
  • If this dependency disappeared tomorrow, how bad would it be? Could you swap it in an afternoon?
  • Is this abstraction making things easier to change, or just avoiding repetition?

None of this means paralysis. You don't need to design every microservice like it might vanish. But developing an instinct for deletion cost with the same way you develop an instinct for performance or readability, it'll quietly make your codebases healthier.


The Code You Don't Have to Write

There's a final point worth making: the easiest code to delete is the code you never write.

Every feature is a liability. Every abstraction is a maintenance surface. Every dependency is a relationship you're now in. The code that doesn't exist has no bugs, no coupling, no deletion cost.

This doesn't mean build nothing. It means be deliberate. When you feel the urge to add a new layer of abstraction, to generalize something that's only been used once, to build for a use case that might never arrive... pause.

Maybe the right move is to wait. To write the minimal thing. To leave room for deletion.

Because software that can change easily is software that can survive. And the secret to changeability isn't clever architecture or brilliant abstractions.

It's knowing that what you built today can be gracefully taken apart tomorrow.

Top comments (70)

Collapse
 
txdesk profile image
TxDesk

I lived this exact lesson recently. Built three discovery paths to find upgrade authority data on the Sui blockchain. Each path was its own module, its own RPC call, its own fallback logic. Shipped with 87 tests, all green.

Then I ran 4 curl commands against live mainnet. Path A called an API endpoint that doesn't exist (DNS failure). Path B queried for blockchain events that Sui literally never emits. Path C used field names from outdated documentation. Three paths, three different flavors of wrong, all invisible in tests because I was mocking the responses I expected instead of the responses the real system returns.

Deleted all three. Replaced with one simpler path that actually works. Tool execution dropped 46% because I stopped making three RPC calls that returned nothing. The code got smaller and more honest at the same time.

The reason deletion was cheap is exactly your point about boundaries. Each path was a single function behind a shared interface. Removing one meant deleting one function and one call site. If those three paths had been woven into each other or shared state, the fix would have been a rewrite. The modularity wasn't there because I planned for deletion. It was there because I followed the pattern from the rest of the codebase. But the effect was the same: when reality disagreed with my assumptions, the cost of being wrong was three clean removals instead of surgery.

"What would it take to remove this?" is going into my review process.

Collapse
 
adamthedeveloper profile image
Adam - The Developer

This is the best real-world example I've heard. 87 passing tests, completely wrong. Oof.

But that last line is the punchline: "the cost of being wrong was three clean removals instead of surgery." That's the whole essay in one sentence. You didn't plan for deletion, but you built in a way that made it cheap anyway.

That's the secret - deletability is often just good modularity wearing different clothes.

Collapse
 
txdesk profile image
TxDesk

"Deletability is often just good modularity wearing different clothes" is a great way to put it. The only thing I'd add is that smoke testing against real external systems is what reveals whether your modularity is actually real or just looks real in tests. My mocks were modular. The real system didn't care about my module boundaries. The mocks passed because I'd designed them to pass. The curl commands passed because the code was actually correct. Two very different statements.

Thread Thread
 
adamthedeveloper profile image
Adam - The Developer

These are the two scariest sentences about testing I've read in a while:

"The mocks passed because I'd designed them to pass. The curl commands passed because the code was actually correct."

Modularity is necessary but not sufficient. Reality is the only review that counts.

Thread Thread
 
txdesk profile image
TxDesk

Exactly. And the worst part is that the mocks feel like safety. You write them, the tests go green, you get the confidence boost, and you move on. The curl commands feel like extra work. But the mocks are testing your model of reality. The curl commands are testing reality. Those are different things, and the gap between them is where the bugs live.

Collapse
 
ndaidong profile image
Dong Nguyen • Edited

Totally agree. I always add this to the AGENTS.md:

Collapse
 
adamthedeveloper profile image
Adam - The Developer

in mine as well ;)

Collapse
 
aloisseckar profile image
Alois Sečkár

out of topic, but does having line "Coding guidelines for AI agents working on this project." helps anything or is it just a nose? Don't agents already assume file called "AGENTS.md" will contain exactly that?

Collapse
 
syedahmershah profile image
Syed Ahmer Shah

The idea of abstraction as a "deletion seam" instead of a scalability bet is a total game changer.

Collapse
 
adamthedeveloper profile image
Adam - The Developer

yeah, it reframes everything.

Scalability bets are guesses about the future. Deletion seams are just humility with a plan. One of those is way easier to get right.

Collapse
 
dariomannu profile image
Dario Mannu

Very good points.

We've been using plugin systems to implement these principles on a daily basis for many, many years.

The entry point of an application does only one thing: loading plugins (modules).

Every feature is a plugin and removing it means just deleting the corresponding file(s).

Here's a mini example using TOPS, for stream-oriented programming.
The router is a plugin, the home page is another, just like other pages, the navbar, the sidebar, etc. In real-life code effects are plugins, too.

Collapse
 
adamthedeveloper profile image
Adam - The Developer

Love this. "Every feature is a plugin" is exactly the bar. Delete one file, done.
Effects as plugins too - that's the hard part most systems get wrong.

Collapse
 
pengeszikra profile image
Peter Vivo • Edited

Easy to delete! Perfect!

There is a level in real life where a company should be deleted from the architecture of the software system because it only plays an uncontrollable proxy role and handles critical operational data at the correspondence level. I don't think we will have the opportunity to get rid of the consequences of a decision made 7-8 years ago even next year.

I'm just a outsorced developer on that project, at the bottom of every decision chain.

Collapse
 
adamthedeveloper profile image
Adam - The Developer

Oof. That's the dark side of this whole conversation. You can design for deletability all you want, but if the organizational decision was made 8 years ago and now a company-sized knot is tied into your architecture... no amount of nice modules gets you out.

Sometimes the thing that needs deleting isn't code. It's a contract. A vendor. A "strategic partnership" no one will admit was a mistake.

That's the level where this philosophy stops being technical and starts being political.

Collapse
 
xwero profile image
david duymelinck • Edited

While the goal is the same I turn the concept upside down. All code is temporary, but there is code that can become permanent.

The idea behind it is that code can become a main staple for the application. Not because nobody wants to touch it, but because with many changes it almost stays as it was when it was introduced. Only taking another direction can earmark it for removal.
Most of the times it is not because the code is robust, but because it is adaptable enough to keep providing value.
Instead of thinking about the removal, try to make the footprint as small as possible.

I do think there is power in looking at code through a deletabilty lens, but I see it more as a consequence of making code lean and mean.
One of the concepts that makes this possible is composability.

Collapse
 
adamthedeveloper profile image
Adam - The Developer

I like this reframe. "All code is temporary, but some can become permanent" — that's not a contradiction of deletability, it's the proof of it. Code that survives does so because it was deletable and just... never got deleted.

Composability as the engine makes sense too. Small, independent pieces that earn their keep.

Collapse
 
codingwithjiro profile image
Elmar Chavez • Edited

"...design for reversibility"

Apparently this hits me harder than what I would have realized. I've been creating side projects and most of the time I don't think of "how to reverse this if I plan to change it again". Being intentional with having an easy save point makes so much more sense. Thank you for this insight!

Collapse
 
adamthedeveloper profile image
Adam - The Developer

glad it landed! The "save point" framing is perfect - you're not planning to fail, you're just making it cheap to change your mind.

That's all reversibility is: a save point you can actually load.

Collapse
 
narnaiezzsshaa profile image
Narnaiezzsshaa Truong

What this essay reminded me of is how much “deletability” depends on who controls the seams. In normal software, we define our own module boundaries. In cloud platforms, the seams are defined for us.

AWS gives you powerful primitives, but the boundaries they create—IAM roles, EventBridge rules, SQS/SNS wiring, CloudWatch alarms—are substrate‑level seams. Once a feature crosses those boundaries, it’s no longer just code you can delete. It’s code plus infrastructure plus permissions plus routing plus monitoring.

At that point you’re not decoupled, you’re embedded.

That’s not a criticism of AWS; it’s just the architectural reality of building on a shared substrate. The deletion cost isn’t in the Lambda function—it’s in everything around it. And that’s why “vendor lock‑in” isn’t really about fear or ideology. It’s simply the natural consequence of adopting a platform where the seams live outside your codebase.

The takeaway for me is that deletion‑oriented design matters even more in the cloud. If you don’t create your own boundaries on top of the platform’s boundaries, the platform becomes the architecture. And once that happens, reversibility gets expensive fast.

Collapse
 
adamthedeveloper profile image
Adam - The Developer

This is a crucial expansion. The essay assumed the seams are yours to control. On a cloud platform, they often aren't.

"Once a feature crosses those boundaries, it's no longer just code you can delete. It's code plus infrastructure plus permissions plus routing plus monitoring."

That's the real lock-in. Not malice - just death by a thousand platform attachments.

The implication is uncomfortable: maybe the most deletable system isn't the one with the cleanest modules. It's the one that avoids deep platform embrace in the first place. Or at least wraps every cross-boundary touch in an abstraction you control, not one AWS handed you.

Cloud makes creation cheap. But it makes deletion expensive in ways that don't show up in the codebase. That's a whole other essay waiting to be written.

Collapse
 
narnaiezzsshaa profile image
Narnaiezzsshaa Truong

What you said about "death by a thousand platform attachments" is exactly the seam I keep circling around. There's a whole essay hiding in that idea—not anti-cloud, just honest about how substrate-defined boundaries change the deletion calculus.

Two angles feel worth writing: platform-defined seams—how cloud primitives quietly become the architecture—and deletion-oriented cloud design—how to build tenant-scoped boundaries on top of a global substrate. They're complementary lenses, and your framing of "creation cheap, deletion expensive" is the perfect starting point.

If you ever want to take it further, the conversation has legs.

Collapse
 
ivannaranjo999 profile image
Iván Naranjo Ortega

Great post! This also makes future refactoring so much cleaner. Following this philosophy, swapping or rewriting would feel way simpler and less prone to introducing bugs.

Collapse
 
adamthedeveloper profile image
Adam - The Developer

Mmm hmm. Refactoring is just deletion + addition. If deletion is painful, the refactor will be too.

Collapse
 
itskondrat profile image
Mykola Kondratiuk

the logging library surgery is real. but deletable-code thinking too often becomes cover for shipping throwaway stuff with no removal plan. choosing the deletion boundary before you build - that gap is what nobody actually does.

Collapse
 
adamthedeveloper profile image
Adam - The Developer

Oof, yes. "No removal plan" is the key. Deletability isn't permission to build slop — it's the discipline to build with exits.

Choosing the deletion boundary before you build is exactly the hard part. Most people read the essay, nod, and keep building like nothing changed. The boundary is where the thinking happens.

Collapse
 
itskondrat profile image
Mykola Kondratiuk

the boundary point is good. I'd also add - if removing it later breaks unexpected things, the boundary was wrong from the start. the exit plan ends up revealing design flaws you didn't know were there.

Thread Thread
 
adamthedeveloper profile image
Adam - The Developer

Sharp. The exit plan as a design audit - I love that.

If you can't delete it cleanly, you didn't build it cleanly. The removal doesn't create the mess, it just shows you where the mess already was.

Thread Thread
 
itskondrat profile image
Mykola Kondratiuk

that inverse reads like a theorem. most teams measure build quality six ways and never run the deletion audit — the coupling you can't undo cleanly is the review that didn't happen.

Some comments may only be visible to logged-in visitors. Sign in to view all comments.