YAGNI stands for "You Aren't Gonna Need It". This principle focuses on delivering software with limited time and resources. Focusing on delivering value.
It adheres to simplicity and avoids unnecessary complexity. It encourages developers to focus on delivering the simplest solution that meets current requirements, instead of trying to assume future needs.
Why YAGNI? What Problem Does This Principle Solve?
- Deadline for requirements not achieved ⏰
- Unused feature or code 😓
- Bloated and Complex code 🤯
These problems often comes from assumptions and predictions, that never even needed or happened.
Cost of the Problems
1. Cost of building 🧑💻
- Time, effort, and resources
- Includes everything from planning to coding and testing
2. Cost of delays ⏰
- Missed opportunities to deliver features faster or create economic impact
3. Cost of carry 🧳
- Carrying unnecessary complexity results in extra difficulty and extra work in adding other features
- Bloated and Complex code that is harder to maintain and not adaptable to evolve
- Unpredictable bugs due to complexity of the code
4. Cost of repair 🔧
- Fixing mistakes, bugs, or poor choices
- Re-adjusting features that weren’t needed in the first place
How to Implement
1. Prioritization and limiting scope 🔎
- Decide what to build and what not to build
- Focus on the importance of each feature
2. Not assuming and predicting future needs 🧙♂️
- Can lead to unnecessary functionality and increased code complexity
- Often results in wasted effort
3. Create simple and minimal codebases 👾
- Easily adaptable to future changes
- Easy to respond to evolving requirements
- Reduces potential risk of bugs
- Easier to understand and maintain
- Less unused code
- Free of assumptions and predictions
4. Know when to refactor 🧹
- Refactoring can simplify your code, making it easier to understand and maintain
// Without YAGNI principles
type User struct {
Name string
PreferredTheme string // Not needed yet
}
func renderUserProfile(user User) {
if PreferredTheme == "Dark" {
fmt.Println("Applying dark theme...") // Not required now
}
fmt.Println("Name:", user.Name)
}
// With YAGNI principles
type User struct {
Name string
}
func renderUserProfile(user User) {
fmt.Println("Name:", user.Name)
}
The Don'ts 🚫
1. Don't become a Sloppy developer 🏖️
- Writes unmaintainable code
- Neglects necessary refactoring
2. Too focused only on requirements and functionality 🤓
- We, as programmers, need to be able to see the broader context
- Also consider code quality, maintainability, and long-term adaptability
Summary 📖
YAGNI is a powerful principle that keeps your codebase lean, adaptable, and focused on real-world needs. By resisting the temptation to build speculative features, teams can ship faster, reduce bugs, and save time and resources.