You Aren't Gonna Need It (YAGNI)
Build a capability when a real requirement needs it, not when you foresee that one might. Keep the code easy to change instead.
Overview
YAGNI stands for You Aren't Gonna Need It. It comes from Extreme Programming (XP). Ron Jeffries' 1998 article states it in one line: always implement things when you actually need them, never when you just foresee that you need them. Martin Fowler traces the phrase to Kent Beck telling Chet Hendrickson, on the C3 project, that a feature he was about to build was not going to be needed.
The principle exists because guessed features are usually wrong, and even the right ones cost money from the day they are written. Jeffries' own reasoning is practical: speculative work pulls attention from what is needed now, spends time and code on a hypothetical, and the guess often never comes true. The best way to write code quickly and with fewer bugs is to write less of it.
Build it when a requirement asks for it
The rule is about features, and it sorts everyday work into four situations.
- A feature is in the current iteration: build it, because it is needed.
- A feature might be asked for next quarter: do not build it; keep the code easy to change instead. The guess may be wrong, and it costs from today.
- A refactoring makes the next change easier: do it. This is not a feature, so YAGNI does not apply.
- A test protects existing behavior: write it. The same reasoning holds: it is an enabling practice, not a presumptive feature.
The difference shows when you follow a guessed need down both roads. Pre-building takes four steps.
- You guess a need and build it now.
- You carry and maintain it until it is needed.
- The need arrives, often shaped differently from the guess.
- You rework or delete what you built.
Building on demand takes three.
- You guess a need and keep the code easy to change.
- The need arrives.
- You build it once, to the real requirement.
Pre-building pays every cost now and often builds the wrong thing. Building on demand pays once, with the requirement in hand.
Interview questions
- How do you tell good preparation from a YAGNI violation?
- What does a speculative feature actually cost?
- How does YAGNI fit with the SOLID principles, especially open/closed?
- When is it right to build ahead of the requirement?
- How do you handle a stakeholder who wants features built just in case?
Sign up free to read the full topic
More Low-Level Design topics
Start free on Cariara · Coding problems · System design studio