The YAGNI (You Aren't Gonna Need It) principle is a software development principle that encourages developers to implement functionality only when it is actually needed, rather than adding features based on assumptions about future requirements. It helps keep software simple, maintainable, and focused on current needs.
- Avoids implementing unnecessary features and speculative functionality.
- Reduces development time, code complexity, and maintenance effort.
Example: If an e-commerce application currently supports only online payments, developers should not build a complex cryptocurrency payment system merely because it might be needed in the future.
Importance of YAGNI Principle
Adding features before they are required can increase development costs and introduce unnecessary complexity. YAGNI helps development teams focus on functionality that provides immediate value.
- Developers avoid spending time implementing features that may never be used.
- Fewer unnecessary components make applications easier to understand, maintain, and modify.
- Teams reduce testing and maintenance effort by avoiding speculative functionality.
- Development time and resources remain focused on confirmed and current requirements.
- Delaying uncertain decisions allows developers to adapt based on actual requirements instead of assumptions.
How the YAGNI Principle Works
YAGNI encourages developers to evaluate whether a feature is genuinely required before implementing it.

Follow these steps to avoid unnecessary features and development.
- Understand the functionality currently required by users or the business.
- Determine whether a proposed feature addresses a real and confirmed requirement.
- Build only the functionality needed to satisfy current requirements.
- Postpone features and abstractions that are based only on hypothetical future scenarios.
- Add new functionality when a concrete need arises and refactor the existing design where necessary.
Example of YAGNI Principle
Consider an application that needs to calculate discounts using a fixed discount rate of 10%.
1. Without YAGNI Principle
The following program introduces multiple discount types even though the current application requires only a fixed discount.
#include <iostream>
using namespace std;
class DiscountCalculator {
public:
double calculate(double price, int type) {
if (type == 1) {
return price * 0.90; // Fixed discount
} else if (type == 2) {
return price * 0.80; // Future discount
} else if (type == 3) {
return price * 0.70; // Future discount
}
return price;
}
};
int main() {
DiscountCalculator calculator;
cout << "Final Price: "
<< calculator.calculate(1000, 1);
return 0;
}
class DiscountCalculator {
double calculate(double price, int type) {
if (type == 1) {
return price * 0.90; // Fixed discount
} else if (type == 2) {
return price * 0.80; // Future discount
} else if (type == 3) {
return price * 0.70; // Future discount
}
return price;
}
}
public class Main {
public static void main(String[] args) {
DiscountCalculator calculator = new DiscountCalculator();
System.out.println(
"Final Price: " + calculator.calculate(1000, 1)
);
}
}
class DiscountCalculator:
def calculate(self, price, discount_type):
if discount_type == 1:
return price * 0.90 # Fixed discount
elif discount_type == 2:
return price * 0.80 # Future discount
elif discount_type == 3:
return price * 0.70 # Future discount
return price
calculator = DiscountCalculator()
print("Final Price:", calculator.calculate(1000, 1))
class DiscountCalculator {
calculate(price, type) {
if (type === 1) {
return price * 0.90; // Fixed discount
} else if (type === 2) {
return price * 0.80; // Future discount
} else if (type === 3) {
return price * 0.70; // Future discount
}
return price;
}
}
const calculator = new DiscountCalculator();
console.log(
"Final Price:",
calculator.calculate(1000, 1)
);
Output
Final Price: 900Problem: The application includes discount options that are not required. These additional branches increase complexity and testing effort without providing current value.
2. With YAGNI Principle
The application implements only the required discount calculation.
#include <iostream>
using namespace std;
// Implement only the required discount
double calculateDiscount(double price) {
return price * 0.90;
}
int main() {
cout << "Final Price: "
<< calculateDiscount(1000);
return 0;
}
public class Main {
// Implement only the required discount
static double calculateDiscount(double price) {
return price * 0.90;
}
public static void main(String[] args) {
System.out.println(
"Final Price: " + calculateDiscount(1000)
);
}
}
# Implement only the required discount
def calculate_discount(price):
return price * 0.90
print("Final Price:", calculate_discount(1000))
// Implement only the required discount
function calculateDiscount(price) {
return price * 0.90;
}
console.log(
"Final Price:",
calculateDiscount(1000)
);
Output
Final Price: 900Explanation: The second implementation supports the confirmed requirement without introducing unused discount types. Additional discount functionality can be added when needed.
Techniques to Apply the YAGNI Principle
Several development practices help teams avoid speculative features and unnecessary implementation work.
| Technique | Description | Example |
|---|---|---|
| Requirement Prioritization | Implement functionality based on confirmed and current needs. | Build essential checkout features before optional recommendations. |
| Incremental Development | Add functionality gradually in small, usable increments. | Introduce new payment methods when they are required. |
| Simple Design | Avoid unnecessary classes, interfaces, and architectural layers. | Use a simple service instead of a complex plugin framework. |
| Continuous Refactoring | Improve existing code when new requirements justify changes. | Extract common logic after repeated use becomes clear. |
| Deferred Decisions | Postpone uncertain technical choices until sufficient information is available. | Select an advanced caching strategy when workload requirements are known. |
Real-World Applications of YAGNI
YAGNI is commonly used in software projects where requirements evolve and development resources must be allocated efficiently.
- Minimum Viable Products (MVPs): Startups develop essential functionality to validate product ideas before adding optional features.
- E-Commerce Applications: Teams implement required checkout and payment capabilities before developing speculative loyalty or recommendation features.
- API Development: Developers expose endpoints for current use cases instead of building unused APIs for hypothetical integrations.
- System Architecture: Teams avoid introducing microservices, complex orchestration, or distributed infrastructure when a simpler architecture meets current requirements.
Challenges of Applying YAGNI Principle
Although YAGNI reduces speculative development, applying it requires balancing current needs with important long-term requirements.
- Deferring important architectural decisions may lead to expensive changes later.
- Teams may incorrectly classify genuinely necessary functionality as optional.
- Adding new capabilities later may require significant changes to existing components.
- Excessively short-term solutions can create designs that are difficult to maintain or extend.
- Developers and stakeholders may disagree about which features are necessary for the current release.

