4 ms·
I use DRY in two ways. The first is that I'm happy to make 2 or 3 copies of a snippet before promoting that to a new function. The second is when I find a bug
by klyrs 6y ago
I use DRY in two ways. The first is that I'm happy to make 2 or 3 copies of a snippet before promoting that to a new function.
The second is when I find a bug in a duplicated snippet. I'll mend the snippet and its duplicates, once or twice before promoting it to a function.
In the rarer (in my line of work) instance that a common snippet gets used with several intrusive variations, I usually document the pattern. It's tempting to use templates, lambda functions, closures, coroutines, etc but far simpler to duplicate the code. But again, if a bug (or refactor) crops up and I need to fix it in many places, then I'll spend some time thinking about abstraction and weigh the options with the benefit of hindsight.