DRY — is good, but not always!
We’ve all had it drilled into us: Don’t Repeat Yourself!
Duplication is evil, they say, and all code must be reused.
The idea is valid. But like every principle in development, it doesn’t work every time.
On one project, we built a universal popup component.
We wanted it to work for every scenario: login, confirmation, errors, settings, invites, and more.
At first, everything was great. DRY. One component. Convenient. Elegant.
But over time it grew:
At some point, this component became a 1000+ line file.
Testing became hard. Maintaining — terrifying. Using it — confusing.
We realized it would’ve been easier to create three separate components:
<LoginPopup /><InvitePopup /><ErrorPopup />They would’ve been 80% identical, but:
formatDate, getAgeFromDate, truncateTextDRY isn’t a law. It’s a guideline.
Sometimes code duplication means readability and simplicity.
Three clear components are better than one universal monster.
Write code your future self and your team can read.
If that means repeating a few lines — so be it.
🤘 Don’t listen to dogma. Use your brain.
Sometimes DRY is hell. And sometimes — salvation.
Learn to feel the difference.
Subscribe to EasyAdvice — and don’t be afraid to write code that makes sense to you.