DRY
Don't Repeat Yourself.
👑 One of the most frequently repeated dogmas in the broader Software Craftsmanship movement.
⚠️ Yet, I dare say it’s the most harmful one.
At least, it was for me. It took me years of struggling with code—trying to separate, generalize, and abstract it just enough to achieve this goal.
Why do I say "struggling"? Because it really was a struggle. I could feel that something wasn’t working. It was exhausting to force shared code to serve the different needs of various clients using it.
🤯 What a relief it was when I came across the concept of "Context."
I realized that two modules (functions, class methods—whatever) sharing what appears to be an identical chunk of code aren’t necessarily the same thing.
👌 And IT'S OKAY to have duplicated code.
Because today, the code may be the same, but since it operates in different contexts, it’s very likely to evolve and diverge over time. And when that happens—when you have to modify shared code used by multiple unrelated modules—you broke more important principles:
❌ Single Responsibility Principle
❌ Open-Closed Principle
DISCLAIMER: I am not saying the DRY principle is bad. This is MY personal realization. It was harmful for ME when I followed it blindly.
👉 But here’s the key point: The rule itself isn’t bad. Encapsulating common code for reuse is a good practice. The issue is how DRY has been turned into dogma and how it is taught to entry-level software engineers—like myself, years ago.
When taught, it shouldn’t be presented in isolation. It should always be explained in the context of SRP and OCP. Code is "repeated" only if it represents the same responsibility.
P.S. Most of you probably know this already, but for those who don’t: The methodology that introduced me to the concept of "Context" was Domain-Driven Design and its "Bounded Context" principle. I probably should have studied it long ago.
This is just my take, and I’d love to hear your perspective: Does this make sense, or do you think it's wrong?
_____
No GPT was used to write this post. Only for grammar corrections.