YAGNI, short for “You aren’t gonna need it”, is a software design principle stating that developers should implement functionality only when it is actually required, not when they merely anticipate that it might be useful later. In programming and software architecture, it acts as a discipline against speculative generality: abstractions, configuration options, extension points and features built for imagined future needs.
The principle originated in Extreme Programming (XP) in the late 1990s, where it was paired with continuous refactoring and automated testing. It sits alongside the KISS principle and the DRY principle as one of the core heuristics that keep a codebase small, understandable and cheap to change.
What YAGNI forbids and what it permits
YAGNI forbids presumptive features, meaning capabilities written today to satisfy a requirement that no stakeholder has yet requested. Typical examples include a plugin system for an application with one integration, a generic rule engine where three if statements suffice, or support for multiple databases when the product runs on one. The principle targets code that exists for a hypothetical caller.
YAGNI does not forbid good engineering practice. Writing tests, keeping functions small, choosing clear names and separating responsibilities are not speculative features; they are what makes later change affordable. Martin Fowler stresses this distinction: the principle applies to capabilities for future requirements, not to effort that makes the current code easier to modify.
The following table separates work that YAGNI rejects from work it endorses.
| Kind of work | YAGNI verdict | Reason |
|---|---|---|
| Unrequested feature | Reject | No user value until a real need appears |
| Extension point for one implementation | Reject | Adds indirection without a second variant |
| Configuration flag nobody sets | Reject | Multiplies test paths and documentation |
| Automated tests for current behavior | Keep | Makes later refactoring safe |
| Refactoring for clarity | Keep | Reduces the cost of the next change |
| Security and data integrity basics | Keep | Current requirement, not a future one |
The cost model behind YAGNI
YAGNI rests on an economic argument about cost of change. When a team builds a presumptive feature, it pays several costs even if the prediction turns out to be correct, and it pays all of them plus removal costs when the prediction is wrong. Experience across many projects suggests that predictions about future requirements are wrong more often than they are right, because markets, users and priorities shift.
Fowler describes four distinct costs. The table summarizes them and shows when each cost is incurred.
| Cost | What it means | Incurred when |
|---|---|---|
| Cost of build | Analysis, coding and testing of the feature | Always |
| Cost of delay | Valuable work postponed while the feature is built | Always |
| Cost of carry | Extra complexity slows every later change | Until the feature is removed |
| Cost of repair | Rework because the guess was partly wrong | When the real need differs |
The cost of carry is usually the largest and the least visible. Every extra abstraction must be read, understood, kept compatible and covered by tests, so speculative code taxes every developer on every change, long before anyone knows whether it was needed.
YAGNI compared with related principles
YAGNI is most useful when it is understood in tension with other design principles. Several neighboring heuristics in software architecture encourage flexibility, and applying them without YAGNI can produce layers of abstraction with no present purpose.
| Principle | Core idea | Relationship to YAGNI |
|---|---|---|
| KISS principle | Prefer the simplest workable solution | Strongly aligned; YAGNI removes scope, KISS reduces form |
| DRY principle | One authoritative representation of knowledge | Complementary; premature DRY can create speculative abstractions |
| SOLID principles | Guidelines for modular object-oriented design | Open-closed design should follow real variation, not guesses |
| Design pattern | Reusable solution to a recurring problem | Introduce a pattern when the problem exists, not in advance |
| Dependency injection | Supply collaborators from outside | Justified by testing today, not by imagined swaps |
A common tension arises with the open-closed principle. A developer may add an interface and a factory so that a class can be extended without modification. YAGNI suggests waiting for the second concrete variant; the rule of three gives a similar threshold for extracting shared code.
Applying YAGNI in daily development
Applying YAGNI requires a concrete decision rule rather than a slogan. A useful test is to ask whether a named user story, contract, regulation or production incident requires the capability now. If the only justification is “we might need it”, the work is deferred until evidence arrives.
The following decision table covers common situations in which teams hesitate.
| Situation | YAGNI-consistent choice | Why |
|---|---|---|
| One payment provider today | Call it directly behind a thin module | A second provider may never come |
| Requested export to CSV only | Implement CSV, skip a format framework | Formats can be added when requested |
| Public API with external clients | Version it from the start | Breaking changes are costly and real |
| Schema likely to grow | Use migrations, not generic columns | Migrations handle change when it occurs |
| Internal tool for ten users | Skip horizontal scaling design | Load does not justify the complexity |
YAGNI works only when change remains cheap. That condition depends on automated test coverage, continuous integration, short release cycles and a team habit of refactoring. Without these, deferring a decision can become expensive, and teams sometimes overcorrect by building everything up front.
Limitations and common misreadings of YAGNI
YAGNI has legitimate limits. Some decisions are costly or impossible to reverse, and deferring them is not prudent. Experienced architects distinguish reversible decisions from one-way decisions and apply YAGNI mainly to the former.
- Published interfaces, such as public APIs, file formats and wire protocols, are hard to change once clients depend on them.
- Data models in production carry migration costs that grow with data volume.
- Security, privacy and compliance requirements are present obligations, not speculative features.
- Misreading YAGNI as a license for sloppiness confuses scope control with skipping tests, documentation or design.
- Overusing YAGNI to reject obviously imminent work, already scheduled for the next iteration, can cause avoidable rework.
The principle is therefore a default, not an absolute rule. Its strength lies in shifting the burden of proof: speculative work must justify itself with evidence, whereas the absence of a feature needs no justification.
Understanding it simply
YAGNI means do not build something until you actually need it. Programmers often feel tempted to add extra options just in case, the way someone might buy a large toolbox before knowing which repairs the house will need.
Most of those extras are never used, yet they still take time to build and make the rest of the work harder to understand. The key takeaway is simple: solve today’s real problem well, keep the work tidy, and add more only when a genuine need appears.
Applied in practice
A small team builds an internal booking system for a clinic with three treatment rooms. During design, one developer proposes a multi-tenant architecture so that the software could later serve other clinics, with tenant identifiers on every table and a configurable rules engine for scheduling.
The team lead applies YAGNI. No other clinic has asked for the software, and the scheduling rules fit into about forty lines of plain code. The team ships a single-tenant version in six weeks instead of an estimated fourteen, backed by automated tests.
A year later, the clinic opens a second location. The real requirement turns out to be shared patient records across sites, not separate tenants, so the speculative design would have been wrong. Because the code is small and well tested, the team adds location support in two weeks, and the outcome confirms that deferring the guess saved effort twice.