principleModeratependingCanonical
Principle: Optimize for deletion
Viewed 0 times
deletabilitycouplingisolationmodularitymaintainability
Problem
Code becomes hard to remove or replace because it's deeply entangled with other parts of the system.
Solution
Write code that's easy to delete:
Litmus test: How many files do you need to touch to completely remove this feature? Fewer = better.
- Isolate third-party dependencies:
# BAD: Stripe API spread everywhere
stripe.Charge.create(amount=1000, ...) # In 50 files
# GOOD: Wrapped in one module
# payments.py
def charge(amount, token):
return stripe.Charge.create(amount=amount, source=token)
# Switching to another provider = change one file- Feature flags over branching:
- Features behind flags can be deleted by flipping a switch
- No merge required, no deployment
- Vertical slices over horizontal layers:
- Feature in one directory > spread across many
- Delete the directory = feature removed
- Avoid shared state:
- Global state makes everything depend on everything
- Pass dependencies explicitly
- Small, independent modules:
- If deleting a module requires changes in 20 other files, it's too coupled
- Aim for: delete the module, update 1-2 import sites
Litmus test: How many files do you need to touch to completely remove this feature? Fewer = better.
Why
The ability to delete code is a measure of how well-structured it is. Deletable code has clear boundaries, explicit dependencies, and minimal coupling.
Context
Software architecture and code organization decisions
Revisions (0)
No revisions yet.