3 ms·
The problem with DRY is that it doesn't tell you how many repetition is too many. Here's my advice: don't refactor when you repeat yourself twice, refactor whe
by sph 4y ago
The problem with DRY is that it doesn't tell you how many repetition is too many.
Here's my advice: don't refactor when you repeat yourself twice, refactor when repeat yourself _three_ times.
Having one chance to copy-paste before DRY'ing your code has been one of my most treasured coding tricks, it'll save you so much time and premature refactoring.
- ramraj07 4y agoAgreed. Sometimes even three times isn’t enough. You’re being paid obscene amounts to make these judgement calls anyway. If all your API does is return two pizza description jsons then keep it that way. If your client is a pizza delivery company and your api is supposed to allow definition and customization of pizza recipes, then you better take your ass to DRY town. Don’t blame the principle when you can’t understand what it is that you’re abstracting. I have time and again gained enormous benefit by pursuing DRY principle to its absolute core. 20x speed and code complexity optimizations, making entire teams obsolete, etc. The most important point is to make sure that your abstractions absolutely match the fundamental principles of the concept you’re trying to represent. No matter how verbose you think it’s getting it’s totally worth it if this is your bread and butter.