A lot of junior developers misunderstand DRY (Don't Repeat Yourself) as a strict rule against any code duplication. To them DRY means:
- never repeat a line of code
- never have two components share similar structure
- never write anything twice
If something looks similar, they feel obligated to merge it, abstract it, or build a “super component” with flags and conditions. Of course, the result is always the same: Overcomplicated, brittle, unreadable code that was technically DRY — and practically unusable..
Pizza Recipes
Imagine if a cookbook tried to follow the the DRY principle to the extreme. Instead of having separate recipes for different types of pizza, it would try to create one giant single pizza recipe that covers every possible variation - one "single universal pizza recipe".
“Use tomato sauce unless you’re making quattro formaggi — in that case, ignore this and jump to the cheese section.
Add pineapple only if not using anchovies or mushrooms. If using both, skip pineapple and go to page 245, see section b.
If using olives, skip basil unless also adding mushrooms…, in that case turn to page 658”
Technically DRY — only one pizza recipe. But completely unusable. In real life, we keep multiple recipes, even if some steps repeat. And that’s correct. Repetition of harmless steps is not a problem. Confusing everything into one monstrosity is a problem. It's perfectly fine to have every pizza recipe start with "Take the dough and roll it out." because clarity is more important than eliminating every repeated line.
IKEA Furniture Manuals
Imagine if IKEA tried to be DRY by shipping one giant instruction manual for all their furniture instead of separate manuals for each product.
“If assembling a chair, skip to page 573.
If your item uses bolt type B2, follow section 19.
If you’re building something with drawers, go to section 1447 unless it’s the office series…”
That would be completely insane and unusable. Instead, IKEA provides individual manuals for each product, even if many steps repeat across manuals. Because clarity is more important than eliminating every repeated step.
The same principle applies to code. You don't search the codebase for every instance of "class extends Model" to merge them into one mega-class. You create many small, focused classes that are easy to understand and maintain.
The DRY principle is about avoiding duplication of knowledge, not avoiding duplication of keystrokes.
- Duplicating logic is bad.
- Duplicating meaning is bad.
- Duplicating rules is bad.
It's not about trying to avoid duplicating structure. It is often the healthy, maintainable thing to do. Don't try to eliminate every repeated line of code by merging unrelated logic, stuffing everything into one mega-component, making endless if-statements, adding flags or creating abstractions nobody understands. That only produces coupled, brittle, unreadable code that is dangerous to change. This is not what DRY means.
True DRY is about removing duplication of concepts and rules, like centralizing email validation, having one shared price-calculation function, using a composable that handles quantity logic, or extracting truly shared behavior. This produces code that is clear, testable, easy to maintain, and respects boundaries.
Remember, we don't have one huge pizza recipe or one giant IKEA manual. Nobody wants that.
Top comments (0)