3 ms·
For me DRY is one of the most important principles for maintainable software. Imagine having to fix a bug at two independent places or having to add or change t
by tcfhgj 4y ago
For me DRY is one of the most important principles for maintainable software. Imagine having to fix a bug at two independent places or having to add or change the same conceptual functionality at two different places (which you may not even be aware, because you don't remember you copied code somewhere else once)
Totally unnecessary bugs guaranteed, and ready to be thrown away after some time, because a change will be harder than a rewrite.
It's enough pain when the effort is too big to avoid (e.g. Js frontend, Rust Backend) it.
Juniors will learn the difference between actual and imagined similarities at some time.
- orthoxerox 4y agoPremature dryness is the real issue, not the principle itself. When you catch yourself fixing the same code in multiple methods again, it's a good time to stop and refactor.
- glanzwulf 4y agoFunny enough this happened to me yesterday. I had to do a small change of code in a component and then when I pushed the code I got an error back. After searching for what was happening, it was actually a code I copied and named "Component2" two years ago when I was starting out. Today I would not have made it the way I did, but in my first month... And thank god for github actions! :D
- MoreQARespect 4y agoIt is fundamental but it's in constant tension with other principles - e.g. cohesion and coupling. I'm pretty sure all of the most fundamental principles of good code are in tension with each other.
- senbrow 4y agoDRY should really be "DRA" - don't repeat abstractions (which admittedly isn't as catchy). The problem with DRY is when abstractions with currently identical implementations are given a single interface, even though they're logically distinct. Then, when those distinct abstractions' implementations need to diverge, you've got a rats nest of references to manually pick through and separate out. Or worse yet , the mistakenly-shared interface becomes parameterized, leading to a horrible mixing of requirements and concepts that may never be untangled if the original intent is lost to time. Obviously DRY is great when you can consolidate multiple implementations that are actually a single abstraction, but it can really go off the rails if the motivation for the mantra isn't understood.