3 ms·
> Yes, you read that right. Duplicating code (a.k.a copy + paste) can be a good thing. No it is never a good thing because the code you write is the code that
by aikah 10y ago
> Yes, you read that right. Duplicating code (a.k.a copy + paste) can be a good thing.
No it is never a good thing because the code you write is the code that has to be tested and managed. If a routine you're going to copy paste 15 times has a bug you might not give a damn but the guy after you who has to clean up the mess might prefer this routine to be only in 1 place. The rule is simple, if some substantial logic is used at 2 different places it has to be refactored into its own component. Just like a variable has to be declared if a data is used at 2 different places, that's basic CS. If one has hard time to figure out what is what then it's a naming and documentation problem, not an "DRY code" problem.
- taurath 10y agoWithin the same project, and when you don't want to handle the coupling costs that can come with generalization.
- karmajunkie 10y agoIf you're still willing to use the word "never" then post again in five to ten years and tell me how you feel about it then.
- tigershark 10y ago10 years ago I had pretty much the same ideas that I expressed in my previous post about copy and paste. Maybe at the time I was much more extreme given the codebase mentioned above on which I was working on. I still don't see any argument that explains why copy and paste should be better than find a better solution, apart from laziness obviously.