News for hackers. Stuff that matters.
Re:Prefer duplication over the wrong abstraction by danjoc on Saturday July 09, 2016 @12:23PM (#12062003)
I see the author's point, but it overlooks code maintenance.

At step 4, where "Time passes" it should read, Programmer A fixes bugs, optimizes, adds features, etc. Repeat.

If the code is duplicated, the maintenance effort is also duplicated or the duplicates diverge significantly making them more difficult to understand in relation to each other. Why does methodA do this, but methodB does that?

Tools can help prevent ProgrammerB and ProgrammerX from coming in and stinking up the place. Set up sonarqube and let it tell them they must pass the quality gate before merging.

Re:Prefer duplication over the wrong abstraction by bluejekyll on Saturday July 09, 2016 @12:48PM (#12062145)
Agreed. I think this is actually dangerous advice. While I agree that the wrong abstraction can cause lots of pain, the repetition of a bug through duplicate code is arguably a worse issue.

One example might be not using an abstraction for accessing filesystem resources in a web based service. You might end up duplicating a ton of code that improperly takes a string from a request without sanitizing it and then have a massive security problem all over your code.

Re:Prefer duplication over the wrong abstraction by thinkloop on Saturday July 09, 2016 @12:57PM (#12062192)
This would not be a candidate for duplication tho, because the underlying intent is also logically the same. Author is talking about things that coincidentally happen to have similar code at the moment, but are fundamentally and logically unrelated, having a high likelihood of diverging in the near future.
Re:Prefer duplication over the wrong abstraction by bluejekyll on Saturday July 09, 2016 @01:04PM (#12062242)
I understand the intent. I still believe the advice is dangerous if improperly applied.
Re:Prefer duplication over the wrong abstraction by therealjumbo on Saturday July 09, 2016 @01:42PM (#12062433)
That's true for all advice, especially in software development.
Re:Prefer duplication over the wrong abstraction by new_hackers on Saturday July 09, 2016 @01:48PM (#12062463)
"Brush your teeth" is dangerous advice if improperly applied.
Re:Prefer duplication over the wrong abstraction by weberc2 on Saturday July 09, 2016 @12:57PM (#12062194)
Programmer A replaced the duplication with a new abstraction at step 3, so maintenance activities can be performed once on the abstraction definition instead of once per copy. It wasn't until the functionality diverged (thereby invalidating the abstraction) that the author advises replacing the abstraction.
Re:Prefer duplication over the wrong abstraction by danjoc on Saturday July 09, 2016 @01:08PM (#12062257)
>Programmer A replaced the duplication with a new abstraction at step 3

Why would deduplication stop maintenance? Unexpected NullPointerExceptions are found. Unexpected UTF-8 string inputs are discovered. An interger overflow is discovered. A memory leak is found in the method. The method is used in a performance critical loop and now must be optimized.

Maintaining code is the majority of programming work that I've witnessed. If multiple copy/paste methods have to be maintained, it always devolves into a mess of technical debt until someone comes along, pays the debt, and pulls them all up into the same abstraction.

Re:Prefer duplication over the wrong abstraction by weberc2 on Saturday July 09, 2016 @01:19PM (#12062323)
> Why would deduplication stop maintenance?

I didn't say it would, I said it would stop repetitive maintenance--meaning you won't have to update many duplicates of the same logic because there aren't duplicates.

I tried to update my comment to be more clear, but I'm not sure that I succeeded. :p