Top
Best
New

Posted by rafaepta 9 hours ago

Prefer duplication over the wrong abstraction (2016)(sandimetz.com)
414 points | 278 commentspage 6
anon-3988 9 hours ago|
The problem with coming up with a rule that works for everyone is that everyone have a different idea of what makes a good abstraction.

Do you want to iterate using for loop or using .iter().step(2).map()?

I would rather have consistency than a mixed bag of levels of abstractions.

doix 9 hours ago||
> Do you want to iterate using for loop or using .iter().step(2).map()?

This isn't really a good example, assuming both can be used to represent the same thing.

The problem with the wrong abstraction is when your abstraction doesn't let you represent something. Then, because of you've already invested so heavily into it, you start contorting the problem to fit your abstraction and it becomes a shit show.

metaltyphoon 9 hours ago||
> Do you want to iterate using for loop or using .iter().step(2).map()?

I don’t think it matters, specially for sort sized loop scopes

williadc 9 hours ago||
The "99 Bottles of OOP" book mentioned at the bottom was an excellent introduction to refactoring. I highly recommend it if you struggle with finding the right data models for the problems you work on.
ozgrakkurt 8 hours ago||
The discussion around this topic would be nicer if the title had "can be" instead of "is".

Otherwise what is better is better and we don't know what we don't know

_pdp_ 6 hours ago||
The biggest mistakes young engineers make is working out a problem from bottom up... i.e. building frameworks and libraries, rather than exploring the problem space which is more chaotic.

You cannot find the edges of the system with structure you don't understand because once the abstraction are set in place solutions often have the same shape as the frameworks which leads to ultimately really bad systems.

The best way is often not the obvious way. Once you reach the edges then you can think how to program the abstraction but that is many versions down the line from the original.

jstimpfle 9 hours ago||
Code duplication is the wrong abstraction too -- unless it's not really code duplication but code that only happens to be similar for some really "unstable" reason.
dofm 9 hours ago|
I would agree that there are good "de minimis" reasons not to abstract code that isn't ready to be abstracted at all. If the pattern has not settled it shouldn't be forced into an abstraction (beyond those that make sure it is e.g. not vulnerable)

But beyond that, any stable abstraction is better than duplicated code.

jeffypoo 7 hours ago||
I've always told engineers to duplicate until the abstraction is punching them in the face.
dmos62 8 hours ago||
If it's duplication, it's the same abstraction by definition. The fundamental unit of programming is intent, not code.
alkhimey 6 hours ago||
The disadvantages of duplication are greatly reduced in the world of AI. From my experience it can easily detect the duplicates and refactor code safely. On the other hand, code without abstractions is easier to read and easier for AI.

With AI, we really need to rethink the clean code principles.

more-coffee 6 hours ago||
Seems to me like the last thing you want to do is worry whether the LLM has a large enough context window to keep an eye on all duplicates. So I'd argue to deduplicate directly, where possible.
aarjaneiro 6 hours ago||
Personally I've seen way more duplication as a result of AI in large codebases
aappleby 8 hours ago||
The smallest amount of simple code that solves the problem wins. Everything else is irrelevant.
andai 5 hours ago|
See also: Muratori, Semantic Compression ("Compression-Oriented Programming")

https://caseymuratori.com/blog_0015

Previously discussed:

https://news.ycombinator.com/item?id=17090319

https://news.ycombinator.com/item?id=36455794

https://news.ycombinator.com/item?id=46183091

More comments...