Prefer duplication over the wrong abstraction (2016)
201–210 of 375 posts
Re: Prefer duplication over the wrong abstraction (2016)
#202I believe that "single source of truth" is a principle that should always be followed. If there's duplicated code where it'd be a bug if they diverge, then you should refactor. It creates a long-distance coupling in your code that may be invisible to future developers until a bug emerges. But with that in mind, I mostly agree with the article: if it's not a violation of "single source of truth", then abstractions are…
Of course, in theory this is true. In practice people tend to avoid ANY duplication no matter what. Especially junior developers, as if duplication would be the root of all evil.
Very similar with patterns. I've often read people protesting that juniors overuse design patterns, yet I've seldom seen a junior (mis)use anything more complex than a singleton, and when they use any pattern, it's usually forced upon them by an opinionated Java framework.
Re: Prefer duplication over the wrong abstraction (2016)
#203Re: Prefer duplication over the wrong abstraction (2016)
#204Earlier quoted context omitted.
You mean you don’t have 300 versions of your badly developed rapidly evolving platform services rotting away underneath the bit you didn’t duplicate?
I don't. Other teams - maybe they do, maybe they don't. Who cares, not me. I have responsibility for services of my team, I think we are doing a good job. Being selfish is the core principle of microservice architecture.
Re: Prefer duplication over the wrong abstraction (2016)
#205You hardly ever change the thing and if you do, changing it in two or three places 'manually' is really not a big deal.
Now changing something fairly often, that affects logic in 50+ places? Then it makes sense to automate with an abstraction so it all flows through the same lines of code.
I know I've personally spent way more time over the years debugging bad abstractions than changing things in a few places.
Re: Prefer duplication over the wrong abstraction (2016)
#206Re: Prefer duplication over the wrong abstraction (2016)
#207I always felt like I abstract and modularize things way less eagerly than other programmers. Was pleasantly surprised to find that LLMs do it mostly my way by default, then again they're also bad at abstracting when it's actually needed.
Re: Prefer duplication over the wrong abstraction (2016)
#208+1 The worst code I had to maintain was code that tried to follow DRY (without the trying to understand what the original intention of that principle was). The only way out of that mess was widespread code duplication.
Re: Prefer duplication over the wrong abstraction (2016)
#209This is like saying "A slow leak is cheaper than a burst pipe" Yes, okay. But with both you will have a bad time cleaning up. There is a third option: good abstractions. I did see this pattern described in the blog in practice a lot (and fell victim to it myself) and I think that in general this comes down to inexperienced programmers. Object oriented programming makes it worse. Teaching these programmers that they s…
Re: Prefer duplication over the wrong abstraction (2016)
#210Earlier quoted context omitted.
> engineers engineer around them with their own solutions When that happens there's a major engineering leadership failure currently in progress, even if engineering leadership isn't aware of it.
Yep, this is why I why I find talking about this tiring. No matter what you say, many people are going to keep reading it as "duplication is always better than abstracting."
EDIT: LLM or not, this is still true. If you have LLMs pumping out tons of duplicate code you're wasting tokens, and probably more importantly wasting engineer hours reviewing duplicate code.
In some cases it might be a fair trade, in moderation. In general it's certainly wrong.