liveBook · Manning

YAGNI principle

As explained in The Coder Cafe

The YAGNI principle, meaning “You Aren’t Gonna Need It,” advises against implementing functionality until it is actually required.

YAGNI means “You Aren’t Gonna Need It.” Build functionality when it is needed, not because a future requirement seems possible. Every speculative feature or abstraction adds code that someone must understand and maintain. section 4.2

The practical default is to solve the current problem with the simplest suitable design. This can reduce complexity and make later changes easier. It does not mean refusing to think ahead; it means asking whether a proposed addition serves a real need or only a guess. section 4.2 section 4.1

Common signs that a design may be getting ahead of its needs include:

  • Abstract classes or interfaces where a simple implementation would suffice. section 4.2
  • Generic types or methods without a current use for their flexibility. section 4.2
  • Features built for hypothetical users, or code unused by production. section 4.2
  • Optimizations in code that does not significantly affect performance. section 4.2

Design for the product idea, not every imagined feature

An online ordering system that starts with a deliverCoffee method might add another method for coffee and food, then more methods as items change. A deliver method accepting a DeliveryList instead expresses the underlying idea—delivery—without implementing speculative ordering features. YAGNI need not force a design tied too narrowly to today’s first requirement. section 4.3

interface Delivery {
  public void deliver(DeliveryList items);
}
class DeliveryList {
  private List coffees;
  // Other items can be added as needed
}

The Java interface takes a DeliveryList, so the delivery operation is not named after one item type. section 4.3

Use YAGNI as a default, not an absolute ban on preparation. Long-term architecture, anticipated user growth, and regulatory compliance can justify planning ahead. The choice is whether that preparation earns its ongoing maintenance cost. section 4.2

How The Coder Cafe covers it

How deep it goes
Defines the principle, lists five warning signs, and discusses benefits and exceptions without prescribing a formal decision procedure.
Examples
Uses an online ordering delivery interface to contrast item-specific methods with a method accepting a domain object.
What it assumes
Defines the acronym from scratch but assumes familiarity with software features, abstractions, and interfaces.
What you can do after
Evaluate proposed features, abstractions, and optimizations against current needs while recognizing cases that warrant planning ahead.
How it connects
Connects YAGNI to premature abstraction, over-engineering, cognitive load, and domain objects.

Also explained in

Compare how 5 books explain YAGNI principle →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of The Coder Cafe. The section links point to the parts of the book it draws on.