It is the discipline twin of Simplicity and KISS — Keep It Simple. While KISS says "make the thing you build simple," YAGNI says "don't build the thing at all (yet)."
What does the YAGNI inequality say must hold to justify speculative building? → pS>Cbuild+Ccarry.
Why does Ccarry make speculation expensive? → it is paid every day the unused code lives.
Does YAGNI tell you to skip input validation on a present endpoint? → No, that's a present requirement.
When do you finally add an abstraction? → On the third real occurrence (Rule of Three).
What does YAGNI stand for?
You Aren't Gonna Need It.
YAGNI core rule in one sentence?
Implement functionality only when you actually need it now, never just because you foresee needing it.
Inequality justifying speculative build now?
p·S > C_build + C_carry (expected benefit must exceed certain cost).
Why is C_carry the hidden killer?
Unused speculative code must still be read, tested, maintained and refactored around — a cost paid continuously even though it delivers nothing.
Why is building later often CHEAPER than building speculatively now?
Later you have the real requirement, so you avoid wrong guesses and rework (C_later < C_build for the actually-correct design).
Does YAGNI mean "no architecture / no validation"?
No — it forbids speculative future features, not design or non-functional needs required by the present.
YAGNI vs DRY difference?
DRY removes existing duplication; YAGNI prevents speculative future code. Abstracting too early to be DRY can violate YAGNI.
When should you finally extract an abstraction?
On the third real occurrence — the Rule of Three.
Recall Feynman: explain it to a 12-year-old
Imagine you're packing a small bag for a one-day school trip. A friend says "bring a tent, a stove, and snow boots — just in case we get lost in the mountains!" But you're going to a park for a few hours. Carrying all that heavy stuff every minute is real work, and you'll almost certainly never use it. YAGNI is just: only pack what today's trip needs. If a mountain trip ever happens for real, you'll pack for it then — and you'll know exactly what to bring.
YAGNI ka matlab simple hai: "You Aren't Gonna Need It" — yaani jab tak abhi, is waqt, kisi feature ki real zaroorat na ho, tab tak usse mat banao. Hum log coding karte time aksar sochte hain "abhi config option add kar deta hoon, kal kaam aayega", ya "interface generic bana deta hoon, future mein Mongo, SQL, S3 sab support karna padega". Lekin sach yeh hai ki future ka tumhara guess zyada tar galat nikalta hai — requirement badal jaati hai.
Ise expected value se samjho: speculative code banane ka benefit tabhi milta hai jab guess sahi ho (probability p, savings S), par cost toh hamesha deni padti hai — banane ki cost plus carry cost (har din us code ko padhna, test karna, maintain karna). Formula banta hai: build karo tabhi jab p⋅S>Cbuild+Ccarry. Real life mein p chhota hota hai aur carry cost daily lagti hai, isliye yeh inequality usually fail karti hai — matlab abhi mat banao, defer karo.
Ek important confusion clear karo: YAGNI ka matlab "kuch bhi proper mat banao" NAHI hai. Input validation, security, error handling jo abhi ki requirement hain — woh toh banane hi hain. YAGNI sirf speculative future features ko rokta hai, na ki present ki genuine needs ko. Aur jab teesri baar wahi cheez sach mein repeat ho (Rule of Three), tab abstraction banao — pehli baar mein nahi.
Bottom line: ek guess koi ticket nahi hai. Jab tak concrete present requirement na ho, code mat likho. Isse codebase chhota, simple, easy-to-change rehta hai — aur jab real zaroorat aati hai to tum behtar, sahi design banate ho.