News for hackers. Stuff that matters.
Re:The Wrong Abstraction (2016) by goto11 on Sunday July 05, 2020 @12:12PM (#23739721)
I'm skeptical because it is really easy to un-share code by copying it into multiple places but it is very hard to unify duplicated code. So I prefer to err on the side of sharing.

But yes, you should be ready to change sharing into duplication if you realize the code is just "accidentally similar" and need to evolve in separate directions.

In practice I have seen a lot more pain due to duplicate code compared to the issue of over-abstracting code, because the latter is much easier to fix.

Re:The Wrong Abstraction (2016) by joeframbach on Sunday July 05, 2020 @12:16PM (#23739739)
On the other hand, it's really difficult to know who is using that shared code. If you make an innocuous change in a shared method, it could affect someone else you don't know.
Re:The Wrong Abstraction (2016) by bcrosby95 on Sunday July 05, 2020 @12:41PM (#23739968)
It's a million times easier than figuring out if those minor differences in duplicate code are accidental or on purpose.

As bad as a flag-laden method might be, you know the intent of all callers.

Re:The Wrong Abstraction (2016) by lambdatronics on Sunday July 05, 2020 @11:13PM (#23744342)
It doesn't have to be that way, it's just because our existing language facilities don't have support for what we need them to do:

"Names are regularly repurposed to point to new definitions, even when the old definitions are still perfectly valid. For instance, a library author might make a function a bit more generic by adding an extra parameter, or decide to switch the parameter order. That's fine, but the old definition was not wrong, so should users be forced to upgrade? No.

Repurposing names is fine; it's hard to come up with good names for definitions, so using an old name for a related new definition often makes sense. The trouble is that existing tooling doesn't distinguish between repurposing a name and upgrading a definition. Unison changes that..." https://www.unisonweb.org/2020/04/10/reducing-churn/#incompa...

Re:The Wrong Abstraction (2016) by TheCoelacanth on Sunday July 05, 2020 @12:30PM (#23739870)
It's very easy with proper tooling.
Re:The Wrong Abstraction (2016) by BoiledCabbage on Sunday July 05, 2020 @12:32PM (#23739888)
Outside of publishing a public API almost any modern language and enviroment should make this easy.
Re:The Wrong Abstraction (2016) by mcintyre1994 on Sunday July 05, 2020 @01:21PM (#23740269)
I find it much easier to find the call sites for a function than to find code that’s duplicating or a variant of the code I just fixed a bug in so we can figure out if the same bug is latent in the duplicates too.
Re:The Wrong Abstraction (2016) by dtech on Sunday July 05, 2020 @02:58PM (#23740984)
Not in any modern language or IDE. Not to mention that would indicate a hole in the test suite
Re:The Wrong Abstraction (2016) by kolinko on Sunday July 05, 2020 @12:17PM (#23739752)
Depends on a specific codebase? I found exact opposite to be true - very hard to reuse code that was abstracted too soon, and abstracting copy&paste the right way is actually easier if you have it in multiple cases and can see how it was used.
Re:The Wrong Abstraction (2016) by hackinthebochs on Sunday July 05, 2020 @12:42PM (#23739972)
How is it harder to copy/paste the helper method and modify as needed, vs tracking down and unifying multiple instances of the same code written slightly differently?
Re:The Wrong Abstraction (2016) by amelius on Sunday July 05, 2020 @12:53PM (#23740058)
Because the multiple instances are concrete while the unified code is abstract.

In general it is more difficult to read abstract code than concrete code.

Also code written using the wrong abstaction can get hairy very quickly (lots of "if" statements for various cases).

Re:The Wrong Abstraction (2016) by fiddlerwoaroof on Sunday July 05, 2020 @01:17PM (#23740243)
In Java, when I hit a bad abstraction, I hit the inline shortcut (command-alt-n) and then evaluate the resulting code with git diff. Other languages may be more manual, but, at worst, you just use ripgrep or similar to find all the relevant use sites and then manually expand the abstraction: this is only really a problem it the function is used hundreds of time: but, in that case, you can always duplicate the abstraction and rename.
Re:The Wrong Abstraction (2016) by sethammons on Sunday July 05, 2020 @12:25PM (#23739826)
My experience lines up with yours. Working in overly and poorly abstracted codebases dramatically hurts productivity. Poorly duplicated code increases the chance for missed patches, but poor duplication has, in my experience, been vastly easier to fix. One codebase comes to mind. Twisted Python. Multiple layers of inheritance, multiple mixins, and major overloading of methods. Just navigating the code was pain.
Re:The Wrong Abstraction (2016) by sagichmal on Sunday July 05, 2020 @01:31PM (#23740339)
> it is really easy to un-share code by copying it into multiple places but it is very hard to unify duplicated code

Code that already exists has a gravity, a presumption of correctness. That presumption is very difficult to overcome, especially for programmers new to the codebase. An abstraction you think of as temporary will be, to those who come after you, simply the way things are done; breaking it apart and re-forming it is, for them, fraught with risk. It's good to keep this in mind as you make commits.

Re:The Wrong Abstraction (2016) by goto11 on Sunday July 05, 2020 @02:19PM (#23740696)
Then the same would be the case for code duplication which really ought to be unified.
Re:The Wrong Abstraction (2016) by sagichmal on Monday July 06, 2020 @09:06PM (#23754548)
I don't think I agree. Identifying an abstraction as leaky and breaking it apart is substantially more difficult and riskier than identifying duplication and creating an abstraction for it.
Re:The Wrong Abstraction (2016) by goto11 on Friday July 10, 2020 @07:53AM (#23790581)
Removing an abstraction layer can usually be done mechanically by inlining the calls. This is a trivial operation. Identifying duplication not trivial since there might be various differences and you have to investigate if they are inconsequential or not.