Top
Best
New

Posted by rafaepta 11 hours ago

Prefer duplication over the wrong abstraction (2016)(sandimetz.com)
437 points | 300 commentspage 7
alkhimey 8 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 8 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 7 hours ago||
Personally I've seen way more duplication as a result of AI in large codebases
aappleby 10 hours ago||
The smallest amount of simple code that solves the problem wins. Everything else is irrelevant.
gaigalas 2 hours ago||
I like the mantra: "prefer duplication over the wrong abstraction".

Combined with another interesting idea "whatever I dislike is wrong", it makes me _always be right_, which is awesome. I can never lose a discussion about abstraction with this powerful combo.

ChrisArchitect 10 hours ago||
(2016)

Some previous discussions:

2023 https://news.ycombinator.com/item?id=35927149

2021 https://news.ycombinator.com/item?id=27095503

2020 https://news.ycombinator.com/item?id=23739596

2018 https://news.ycombinator.com/item?id=17578714

2016 https://news.ycombinator.com/item?id=11032296

sebastianconcpt 10 hours ago||
Oh the self-contradiction here...

Generalizing this in the abstract is a wrong abstraction.

hedora 10 hours ago||
I’ve seen code bases that evolved like that. The problem is almost always outside the abstraction that has a pile of conditionals.

Usually, some moron decided to copy paste things a few levels up and then the top half of the system metastasized into two parallel universes of broken garbage.

For instance, one might decide to perform auth later in the flow so unauthorized handlers can run and set a “this requires auth” bit that defaults to false, and the other flow could add a forged auth header before the auth step.

Now, the auth handler needs a “allow forged header” flag and a “already authenticated” flag.

I’ve seen that grow to a half dozen cases until massive production dataloss occurred. A buggy client tried to delete something local to their account without specifying a userid as a parameter (this codebase was garbage!) and deleted the something for all users instead.

I can’t remember how the dataloss was “fixed”, but it definitely wasn’t “all requests go through a simple auth check, and all handlers declare/implement their auth requirements in the same way”.

Getting a design approved to require a user id be specified exactly once for account-level operations was fantasy land for that team. (Most hires with any sort of engineering talent bounced in under a year.)

Anyway the “abstractions are hard so copy paste” approach did provide job security for the lifers on that product. I can’t imagine them holding a job elsewhere, but they were completely immune to layoffs (hostage style).

This is a pretty valid approach if you’re an agent hired to perform industrial sabotage, or if you keep replacing keyboards after you knaw through the corner.

andai 7 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

TexanFeller 10 hours ago||
> Code duplication is far cheaper than the wrong abstraction

Very true in some sense, but I continue to encourage DRY-bias because I've literally never seen teams duplicate code responsibly and later dedupe it when it's the right time. 95% of the time this sentiment is quoted to justify shipping quick slop and stable reusable bits are never extracted into a shared lib later.

bluefirebrand 10 hours ago|
In my experience if your organization can't commit to doing WET (write everything twice) code then it probably also will fail at doing DRY (don't repeat yourself) code

Maybe this is an area where AI can help identify duplicate code though to show opportunities for de-duping

mcculley 9 hours ago||
Yes, if your programming language/environment is weak.
mohamedkoubaa 9 hours ago|
Duplication is often a small price to pay for isolation
More comments...