Build the simplest thing that works. Resist the urge to over-engineer.
XP has a mantra: Do the simplest thing that could possibly work.
This isn't about being lazy or writing hacky code. Simple code is often harder to write than complex code. It requires:
Simple code is:
Complex code is:
Simple Is Hard
"I would have written a shorter letter, but I did not have the time." —Blaise Pascal. Simple code requires more thought, not less.
YAGNI is the principle that you should only build what you need right now.
Don't add:
Why? Because:
The XP bet: If you need something later, you can add it later. With TDD, refactoring, and CI, change is cheap. So don't pay for the future before you have to.
This is a radical idea. Traditional software engineering says anticipate change and design for flexibility. XP says wait until you actually need it.
The team needs to send emails. They implement sending via SMTP. Later, they need to send via SendGrid. They refactor. Total cost: less than building a pluggable email abstraction up front.
The team needs to send emails. They build a generic 'MessageProvider' interface with pluggable 'MessageTransport' and 'MessageFormatter' abstractions. They only ever use SMTP with one format. The abstractions slow down every change.
Kent Beck defined simple design as code that:
1. Passes all the tests The code works. This is non-negotiable. A beautiful design that doesn't work is worthless.
2. Reveals intention The code is easy to understand. Good names, clear structure, readable organization. Someone new can pick it up and understand what it does.
3. Has no duplication (DRY) Each piece of knowledge is expressed once and only once. Duplication creates maintenance burden and bug risk.
4. Has the fewest elements No extra classes, methods, variables, or abstractions. Everything that exists has a reason to exist.
The rules are in priority order. Passing tests trumps everything. But once tests pass, favor clarity over DRYness. And only add elements that serve the first three rules.
Simple design doesn't mean no design. It means incremental design—evolving the design as you learn.
The process:
This is why XP emphasizes refactoring so heavily. If you can't change the code safely, you can't do incremental design. You're stuck with whatever you built first.
Big Up-Front Design (BUFD) fails because:
Incremental design succeeds because:
When you feel the urge to add an abstraction, ask: "Do I need this now, or am I guessing?" If you're guessing, wait.
Simple design doesn't mean avoiding all complexity. Sometimes complexity is necessary.
Add complexity when:
Don't add complexity for:
The difference is between essential complexity (inherent in the problem) and accidental complexity (introduced by your solution). XP minimizes accidental complexity by refusing to build for imaginary requirements.
When you do need an abstraction, let it emerge from removing duplication. The "Rule of Three" is helpful: don't abstract until you see the same pattern three times. By then you understand the actual variations, not imagined ones.