YAGNI (You Aren’t Gonna Need It) is a principle that advocates building only what you need now, not what you might need in the future.
Core Concept
Don’t add functionality or create abstractions based on speculative future requirements. Build the simplest thing that works for current needs.
Why YAGNI Matters
- Reduces Complexity: Less code to maintain and understand
- Faster Development: Focus on immediate requirements
- Lower Risk: Avoid building wrong abstractions for imagined futures
- Easier Change: Simpler codebases adapt more easily when requirements actually change
YAGNI in Practice
Don’t Build Speculative Features
// BAD: Building for imagined future
public class User
{
public string Email { get; set; }
public string SecondaryEmail { get; set; } // Not needed yet
public string TertiaryEmail { get; set; } // Speculative
public List<string> AllEmails { get; set; } // Over-engineering
}
// GOOD: Build what's needed now
public class User
{
public string Email { get; set; }
}Don’t Create Premature Abstractions
Wait until you have 3+ instances of duplication before abstracting (Rule of Three).
Balancing YAGNI
YAGNI doesn’t mean:
- Write bad code
- Ignore design completely
- Never plan ahead
- Avoid all abstractions
YAGNI means:
- Build for current, known requirements
- Refactor when new requirements emerge
- Keep design simple and focused
- Add complexity only when justified by actual need
Resources
Related Concepts
- DRY - Avoid hasty abstractions (AHA)
- KISS - Keep it simple
- Refactoring - Evolve design as needs emerge
- Design Principles
- Good Software Practices