Boat Anchor
Unused code kept “just in case”.
“Code that serves no purpose but remains in the codebase.” – Brown et al.
Code that serves no purpose.
Signs of Use (Symptoms)
- Classes or methods with no callers in the entire project.
- Variables defined but never used.
- Libraries imported but not used.
Why it is bad (Consequences)
- Cognitive Load: Developers waste time reading/maintaining useless code.
- Confusion: “Do we need this? Does it do something magic?”
- Bloat: Increases build times and bundle sizes.
Why it happens (Root Cause)
Speculative programming (“we might need this later”) or forgetting to cleanup after refactoring.
When it might be okay (Exceptions)
- Public library APIs (functions exist for consumers, even if library doesn’t use them).
Explanation
Problem
A specific feature was removed, but the helper classes for it were left behind because “it was good code”.
The Flaw
YAGNI (You Aren’t Gonna Need It). Version control exists for a reason.
Real world analogy
Keeping a broken toaster in your kitchen because “maybe I’ll fix it someday” or “maybe I’ll need parts.” It just takes up counter space.
Refactoring Solution
- Delete it: Use your IDE to find unused references and remove them.
- Git: Relies on source control to restore if ever needed.
Pros and Cons (of the Antipattern)
| Pros (Why people do it) | Cons (The price you pay) |
|---|---|
Comparison
- Related Antipatterns: Lava Flow, Dead Code, Speculative Generality.
- Related Principles: YAGNI, KISS.
Code example
Typescript
Bad (The Antipattern)
Good (The Fix)
PHP
Bad (The Antipattern)
Good (The Fix)