3 ms·
That's true, but my recommendation to newer programmers is still learn to practice radical DRY first, then as the final polish, learn when to back off (i.e., "t
by jerf 12y ago
That's true, but my recommendation to newer programmers is still learn to practice radical DRY first, then as the final polish, learn when to back off (i.e., "the rule of three"). Far, far more programmers do not understand DRY, and accidentally avoid over-sharing by virtue of simply having bad coding practices in general and rewriting everything every time than overdo DRY.
Someday I ought to write up a post about this sort of thing on my blog. I think part of our eternal warfare about coding practices (though by no means all of it) comes from the fact that there are different practices that should be followed by someone with two years of experience than someone with ten. For instance, I think test-driven development is great... for a new programmer. It is something that you will outgrow eventually. But in the meantime, TDD will teach you good design much more quickly than you would have learned any other way, and in the meantime, you'll produce better code than you would have otherwise just blundering around in the traditional manner. And for myself at coming up fast on 20 years of experience, I don't do "TDD" but I still do a lot of automated testing (and the damned code keeps surprising me, and punishing me whenever I think this time for sure I can skip the tests...).
So too here with DRY; you may someday outgrow it, but you'll learn better design and programming skills in the meantime, and in the end I still think you'll find the optimum point is closer to DRY than farther from it. I think that's because beyond the surface gloss of DRY from a perspective of simply "not repeating code" you come to understand how a bit of code can embody a concept, and what DRY is really trying to teach you to avoid is having a concept live in two places, rather than raw code repetition, and that idea will stick with you until the end of your career. But to get to that level of understanding, practice radical DRY until you understand.