Concept · Code design

YAGNI: you aren't gonna need it

Don't build features or generality until a real requirement needs them — but do keep the tests and structure that make adding them later cheap.

2 minyou aren’t gonna need itspeculative generalitypremature abstraction

YAGNI — "You Aren't Gonna Need It" — comes from Extreme Programming: don't implement something until it is actually needed, not when you merely foresee that it might be.

The cost of building it now

Martin Fowler breaks the cost of a speculative feature into parts:

  • Cost of build: the time spent on it instead of on what's needed now.
  • Cost of carry: every engineer reads around it, tests it, upgrades it and debugs it, for as long as it exists.
  • Cost of delay: the needed features that shipped later because of it.
  • Cost of repair: when the real requirement arrives, it's usually different from the guess, and the speculative design must be reworked or removed.

Even when you guess right, you paid carry costs for nothing until the day it was needed.

Typical violations: a plugin system before a second plugin exists, multi-tenancy "for future enterprise customers", configurable everything, an abstraction layer over the database "in case we switch", a queue for a job that runs once a day.

What YAGNI is not

YAGNI targets presumptive features and speculative generality. It does not mean:

  • Skipping tests, error handling, logging or security.
  • Writing tangled code because "we'll clean it up if needed".
  • Ignoring a requirement that is known and scheduled.

In fact YAGNI depends on those practices. You can afford not to build the plugin system today because good tests and a modular structure make adding it later cheap. Without them, every deferred feature becomes a painful rewrite, and engineers respond by over-building up front.

Applying it

Build for today's requirements in a way that's easy to change. When you're tempted to add a hook "for later", write the idea in a ticket or an ADR instead. The same reasoning applies at the system level in when not to add infrastructure, and in code alongside KISS.

Learn it in depth