YAGNI (You Aren't Gonna Need It)
YAGNI (You Aren't Gonna Need It) is software development principle according to which you shouldn't implement functionality you don't need yet. Simply put, don't write code and create infrastructure "for future" if there's no immediate need for it now.
Main Idea
-
Avoid excessive functionality
When we try to anticipate all possible code usage scenarios in advance, we risk complicating architecture. These "extra" parts may never be needed, and time spent on their development and maintenance will be wasted. -
Focus on current tasks
YAGNI principle helps not to get distracted by hypothetical features, but concentrate on current real project needs. When need for additional functionality actually arises, you'll implement it more correctly and efficiently.
Example
Imagine we have task to create function for processing data list. We know for sure that current requirements are simply to filter array by certain condition and return result.
// Bad (accounting for possible scenarios that aren't needed yet)
function processData(array) {
// Filter
let filtered = array.filter(item => item.active);
// Sort by multiple fields (though only filter is needed now)
filtered.sort((a, b) => a.priority - b.priority || a.id - b.id);
// Store additional statistics (not required by spec)
const stats = {
count: filtered.length,
maxPriority: Math.max(...filtered.map(f => f.priority))
};
// Assume debug log will be useful in future
console.log("DEBUG: processed data", filtered, stats);
return filtered;
}
// Better (only what's needed now)
function processData(array) {
return array.filter(item => item.active);
}
In this example, we only implement what's required by current requirements. When need for sorting or statistics actually arises, we'll add it then, based on real needs and requirements.