Video in progress
What is YAGNI, and when does it stop you from writing code "for the future"?
YAGNI (You Aren't Gonna Need It) means not writing a feature in advance that you don't need now because it "might come in handy later". Such code eats time, has to be tested and maintained, and often is never used, or the guess turns out wrong.
📖 Answer
A typical case: the task is to store an order in som. A developer thinks "maybe we'll need dollars too" and adds currency conversion, a rate table and a CurrencyStrategy interface. Half a year later the business asks not for currencies but for installment payments. The code that was written is dead weight, but it has to be taken into account in every refactoring.
Where YAGNI applies:
- a new parameter, configuration setting or optional mode: don't add it without a concrete requirement;
- writing a "generic" framework: if there is one user, a plain class is enough.
What YAGNI does not mean:
- skipping tests, error handling, logging or security checks: those are needed now;
- a design that makes change hard. If the code is simple and clean, adding a future requirement is cheap, and YAGNI relies on exactly that.
In places where change is expensive later, like a database schema or an external API, a bit of up-front thinking is justified.
Sign up to mark studied questions and save your progress.