
YAGNI
You Aren’t Gonna Need It
“Always implement things when you actually need them, never when you just foresee that you need them.” – Ron Jeffries
Do not add functionality until it is practically necessary.
When to use
When you find yourself thinking “I should also add support for X, just in case…” or “We might need this later.”
Why it matters
- Cost: You waste time building things nobody uses.
- Maintenance: You have to maintain code that nobody uses.
- Cognitive Load: Dead/unused code confuses developers.
Signs of Violation
- “Scaffolding” code for features that are planned for “Phase 2”.
- Abstract base classes with only one child class.
- Methods that are never called.
Explanation
Problem
Speculative generality increases entropy. You guess wrong about what you’ll need, and then you have to refactor the wrong guess later.
Solution
Implement only what is required now.
Real world analogy
Packing for a trip. Don’t pack a parka for a trip to Hawaii “just in case” there’s a freak blizzard. You carry extra weight for no reason.
Pros and Cons
| Pros | Cons |
|---|---|
Comparison
- KISS: YAGNI is a subset of KISS (keeping the feature set simple).
- Lean Software Development: YAGNI is a core practice of Lean (Eliminate Waste).
Code example
Typescript
Bad (Violation)
Good (Adherence)
PHP
Bad (Violation)
Good (Adherence)