

Lesson 01 · 12 min
DRY, KISS, YAGNI
Three short rules that remove half of the extra code, and the case where DRY hurts.
12 minLesson 1 of 5Practice includedAsk AI on any point
Programming principles are not laws but compressed experience: what usually breaks a year later and how to avoid it. Let's start with the three shortest ones. They come up in every interview, and they are the ones most often applied wrong.
DRY: don't repeat yourself
DRY (Don't Repeat Yourself) says that every piece of knowledge about the system should live in one place. It is about knowledge, meaning a business rule, a formula, a constant, not about identical lines of text.
Now when marketing changes the discount threshold, you edit one line. In the first version you edit three places and are sure to forget the fourth.
When DRY hurts: the wrong abstraction
Two pieces of code can look the same but mean different things. If you merge them, they start changing for different reasons, and the shared function grows flags.
KISS: keep it simple
KISS (Keep It Simple, Stupid) asks you to pick the simplest solution that works. Simple code is easier to read, test and delete. Cleverness rarely pays off.
YAGNI: you aren't gonna need it
YAGNI (You Aren't Gonna Need It) forbids writing code "for the future": a plugin system for one plugin, a setting nobody changes, a base class for a single child. You have to maintain that code right now, while the need it was written for often never shows up, or shows up in a different shape.
- DRY is about knowledge, not identical lines.
- KISS is about the next person understanding the code in a minute.
- YAGNI is about not paying today for a feature that may never exist.
Check
Lock it in before you move on
1. What does DRY actually forbid?
2. A shared function has grown four boolean flags. What does that most likely mean?
3. Which option is closer to KISS?
4. You are asked to add CSV export. What violates YAGNI?