3 ms·
And often the process of de-duping repeated code later on isn't as bad as DRY purists make it out to be, especially since it can be done incrementally. Example:
by xnx 6y ago
And often the process of de-duping repeated code later on isn't as bad as DRY purists make it out to be, especially since it can be done incrementally. Example: If you have similar functions in 7 places, you can consolidate them one by one. If you have 1 function used in 7 places, you have to consider all implications for all of those code paths.
- azundo 6y agoThis seems like an equivalent duality to me but in the case of seven independent functions you're much more likely to miss considering a case. If behavior changes for one you likely should be considering if that change applies to all the others.
- Ma8ee 6y agoBut when you set out to do that you first have to make sure they really are identical, and since everything from indentation to names often differ it might not be so automatic. And then you do find differences, and you have to figure out if they are there by accident because someone forgot to implement a fix or a change in some places or if the differences are intentional. On the other hand, if you realise your abstraction was bad, duplicating a function is always trivial.
- chousuke 6y agoIn my experience, the "later" may come too late. I've seen code copy-pasted and slightly modified over a dozen times, sometimes without even eliminating dead code! Copying a function or even a whole file is fine if you actually take a moment to consider whether it needs refactoring or not, but more often than not people will just copy and bash at the code until things work without actually making a conscious choice to duplicate code over refactoring.