Twitter | Search | |
Sam Ferree Dec 17
I’m calling for an end to holy war against code duplication. We convince young developers and engineers that it’s the worst thing ever, when time teaches all of us that it is, the vast majority of the time, duplication preferable to dependency.
Reply Retweet Like
Tom Forsyth
My usual process is this: 1. Write code. 2. Copy-paste code, modify for new use. 3. Copy-paste code again, modify for new use. 4. THEN WHEN THEY ALL WORK consider if all three uses could be sensibly merged. ...and quite a lot of times the answer is "no" because of divergent uses.
Reply Retweet Like More
Duncan Hopkins Dec 23
Which is fine when you are the only one in the code. In a commune of devs, trying to keep one block of code instead of the 1st copy/paste is more likely to end up with reusable code block?
Reply Retweet Like
Tom Forsyth Dec 23
What makes you think my advice is for the solo coder? I haven't been "the only one in the code" in twenty years.
Reply Retweet Like
H DC Dec 23
Keeping 3 copies of the code doesn't mean they are not reusable, it means they can't be efficiently and cleanly merged.
Reply Retweet Like
Tom Forsyth Dec 23
If they can't be cleanly merged, then merging them is probably not the right thing to do - the use cases are too different. Trying to merge them is square-peg-in-round hole.
Reply Retweet Like
Martin Ankerl Dec 23
I'm currently enjoying this process: 1. Write code. 2. Adapt it a bit more generic so it supports another use case. 3. Make it even more generic so it supports yet another use case 4. Throw everything away because it got to complex and too slow 5. Replace generic version with 1
Reply Retweet Like
Tom Forsyth Dec 23
These are two possible paths towards the same enlightenment. It is unclear which is the shorter.
Reply Retweet Like
Nicolas Dec 24
when I do this, I put some unique tag has doc that is shared by the copies, so that I can compare them (not allowed to do so at work yet)
Reply Retweet Like
Tom Forsyth Dec 24
I follow the example of Tom Ireland from Muckyfoot who would use the names of fruits, e.g. // This code needs to do the equal-and-opposite thing to some other code. // Search for the word "pineapple" to find both occurrences and keep them in sync. Dumb, simple, works.
Reply Retweet Like