4 ms·
Duplication is bad. In fact, duplication is one of the most dangerous mistakes in coding. I have to disagree with this; the article feels lofty in its assumpti
by tflinton 3y ago
Duplication is bad. In fact, duplication is one of the most dangerous mistakes in coding.
I have to disagree with this; the article feels lofty in its assumption that when you start to program you know what to abstract. More often people begin abstracting due to a misguided axioms like "DRY" rather than to solve a problem with a real cost benefit trade off. DRY as a goal in itself is fairly dangerous.
I can't count how many convoluted and confusing frameworks people have put together under this misguided perspective. It's not atypical for an abstraction born of "DRY" motivations to be more code and brittle than just copying and pasting 2 lines in 15 places.
Not to say abstractions are inherently bad, but to the point of abstracting for the sake of DRY is a mistake.
- lolinder 3y agoThe problem is with being either dogmatic or thoughtless in either direction. I've seen what you're talking about: people combine code religiously because of DRY, leading to insane pyramids of abstractions that are impossible to modify. However, I've also seen people copy and paste everything they ever need. When that happens, those offshoots gradually evolve independently from one another, and introducing a proper abstraction becomes a huge slog. I've spent hours reading through git blame trying to piece together a phylogenetic tree of the various copies of the same code so we can ensure that the new abstraction contains all relevant features and bug fixes. I wish those developers had thought more carefully about DRY. I think the best balance is to use these catch phrases as principles to guide your decision making, while being willing to make exceptions when they don't apply. If DRY makes you think for a second before copying a piece of code, it's done its job, even if you decide that this situation really does call for a copy.