Sometimes syntactic duplication can give you a hint to underlying semantic duplication. But it's no more than a hint.
DRY doesn't mean don't repeat a similar looking block of code, it means try to structure your code so that each element of the design has a single representation.
There's no shortcut to good design where no thinking is required, much as a lot of people seem to wish there were.
What do you mean, Claude just told me my architectural ideas were terrific and we're halfway through implementing a restructure of the company's codebase!
You know what they say. The first 50 percent of the restructure accounts for the first 50 percent of the development tokens. The remaining 50 percent of the restructure is approached asymptotically as tokens→∞.
Absolutely. The rule of thumb is that two things should be abstracted together iff they should change together. The down-sampling constant matching the upweighting factor? Don't repeat yourself. Needing a half-dozen subtly different circular buffer definitions? Circumstances vary, but repetition is probably fine. Two pieces of code which are literally identical? As you said, the syntactic duplication suggests there's an underlying semantic duplication you might want to iron out, but if the two callsites really want the potential for independent behavior then byte-for-byte code duplication can make more sense.
But, like the rest of software, even that's just a guideline. Suppose you've been painted into a corner where code needs to be synced between languages. There are solutions, but especially if it happens rarely then those solutions might be a lot more expensive than just a comment at both locations.
Won't disagree with that, that's why the rule of 2-3-4 is good, don't bother for 2 instances, consider if it really needs an abstraction at 3 times, at 4 it's probably time before things grow out of hand.
Because when you have 20+ repetitions you start needing buy-in for fixes because the testing needed might be beyond something simple.
We are exactly where the hypothetical bank is. Our large outer company gobbled up nine or ten smaller companies with disparate stacks (PHP, Haskell, C#, a few others). After a couple years of integrating through shared APIs, new management is trying to force us all into a single platform - Go and Node+React.
We have thousands of years of combined experience in our various technologies and we are to throw that away in the name of "unity" for a stack literally no one in the company was using but "it should be good for AI"
A bigger part of the positives of repeating yourself is that yourself is plural in this case and other people kind of suck and solving your own problems should be easy.
As an example, I put in a request with the platform team to set the UI toolkit to internal instead of private so it can be more easily accessed cross organization. I have been waiting like six months. No one knew who was in charge of it. ALL our repos have been mandated internal for years so our disparate orgs can read each others code. AFAIK we're the only team that actually lives up to it.
I was with them right up until the admonition against standardizing the UI components. This is not an all-or-nothing proposition. You build a standardized library incrementally, and you slowly migrate codebases over to use them. I've seen some pretty horrendous UI mish-mash in what should appear to be a single application, because each piece was done independently and then stitched together.
You end up with drifting implementations that may or may not come from the same root at different points, where the same fix has to be applied multiple times as each team learns the lessons for what not to do, etc. Effectively what DRY is about.
I got rid of about six years worth of technical debt on exactly this in our frontend last Friday. All it took was a few AI prompts. These types of issues are just melting away now.
Code duplication is fine as long the duplicates don't drift apart. Keeping them in sync is a bit tedious for people. And people tend to cut corners. So there's a potential to end up having to fix the same kinds of issues several times. But with AIs doing all the tedious work, staying on top of that is pretty doable. It's more a question of whether that's a good use of time and tokens. You could just make it fix things properly.
In the code base I mentioned, we had a few different component libraries that at some point were selected, used, and then later abandoned. We also had taken into use tailwind at some point but we never completed the upgrade to tailwind 4. And we had a bunch of manually styled html as well. It's an application with a lot of different functionality, lots of different screens, etc. So there was a bit of pressure to not break things. I fixed all of that in a few prompts. The application still looks and feels the same but is much more consistent in terms of look and feel (we had several varieties of buttons and input fields with subtly different behavior). We found and fixed a few minor issues since then.
reminds me of WET: Write Everything Twice. Instead of immediately jumping to DRY, actually write out the two similar tools, then see what actually makes sense to combine into a shared dependency.
Yes, writing it twice is the perfect way to figure out the right level of abstraction for your project, and how extensible your components need to be. Try to do it with only one instance in front of you, and you end up with all sorts of unnecessary abstractions "just in case".
If you find yourself writing it a third time, on the other hand, you should seriously start consolidating.
my version of this is that, as it is getting closer to user perceived layer, use WET, as it move away from user preceveid layer and toward system level, use DRY.
I've always found DRY to be more useful when applied to data rather than code. Eg don't have two versions of an enum, or a mapping, or the information in some database.
In some cases DRY is also related to parse-don't-validate. Don't repeat validation all over, but have a single canonical parser and a single canonical data transfer object. Typescript frontend+backend makes this even easier.
What I'm missing here, is the security aspect. The author does mention that "there are capabilities, such as DevOps, that are best handled centrally", but I'd expect Mike the VP to put security in the platform team's responsibility, as well as in each team.
The sentiment is somewhat understandable, especially in the world of fast-moving AI-enabled companies all around us. The example doesn't really sound motivating out of the gate.
> All three teams adhered to the corporate branding guidelines, so their products look and feel reasonably similar. They also work fairly well and were shipped on time.
This is the opposite of how things play out in most of the world's large companies, from any major bank to supposedly tech-savvy giants like Google. Every time you cross an app boundary or even a team boundary within a single product, all bets are off. At best, the UI differs in small, annoying ways (button styling, UI element rounding radii), or at worst, you need to go through separate login and payment flows.
> whenever the user switches from the account view to the investing tab, a whole new JS framework is loaded. But, given all other factors, this is an acceptable trade-off.
I guess it's acceptable if you are going from one major product to another, but accepting this when switching between parts of an application that are supposed to be coherent (same banking app, same money involved) tells the customer that you don't care about their experience that much. Accepting this also massively increases the chances that the UX will be different, since frameworks tend to come with their own patterns that shape developer thinking.
Of course, it's OK to repeat yourself as many times as needed to keep shipping products that affect the bottom line of the business and help customers achieve more. At the same time, as a company transitions to multiple products or breaks up the monolith of its main product, it should also start building the DNA for maintaining a coherent UX. This is less about using the same technologies under the hood and more about crystallizing the foundational API shapes and packaging them in a way that allows teams to offer customers a consistent set of UX expectations across internal company boundaries.
In practice, this means that some choices have to be made in a BDFL-style fashion: one general-purpose OLTP database with a preferred way of interacting with it (ORM or not), one JS framework with components supporting shared data structures (with escape hatches for specialized use cases), and one opinionated design system covering the vast majority of use cases across the company's major products.
I thought this was ancestry.com and I was like "yeah repeat yourself by having kids i guess, thats kinda how ancestry works", why is this on hackernews?
Even the DRY principle isn't a hard and fast rule, and in fact most experienced engineers will say that two copies of duplicate code shouldn't be "DRY-ed up". Most set the max at three copies, because "DRY-ing up" code before that point ends up being counter-productive.
Similarly here, except the author isn't talking about code, but systems made out of code. And they're not saying "don't get rid of repetition" ... they're just saying sometimes repetition serves a good purpose, so don't try to "DRY" everything up.
Well... remembering to ask "did you fix it everywhere?" is strictly harder than having only one place, if you don't introduce too much contortions to bring that about.
It's a fairly old acronym replacement after everyone realized "don't repeat yourself" was like "premature optimization" - and misleading people. Nothing wrong with a little repetition and a perfect abstraction is likely a wasted investment. There was also "do repeat yourself twice" and "don't repeat yourself thrice" (on the third copy.. think about optimizing)
As I often like to say when DRY comes up, the fact is I've wasted way more time over the years fixing unforeseen bugs in abstraction layers than I would have making changes in two places sometimes. After a while you realise simple is usually better.
But conversely, with two implementations you can change one if needed without affecting the other.
I've had this happen a few times, you DRY an abstraction and then discover that the cases you thought were the same are slightly different. Now you have to add parameters or logic and change or at least test everything it touches.
N (initially) copied implementions does introduce the risk of 'forgot to update this one' bugs, but these bugs are about as simple as it gets to find and fix.
Abstractions on the other hand introduce the risk of 'what random thing am I going to break by changing this?' bugs which are typically much harder and more time consuming to find and fix. Further, the risk is recursive, as the fix might break yet another thing.
I'd maybe agree with the gp that instances of the former are as common as the latter. But to my original point, they just waste far less time.
I certainly know which class of bug I'd prefer to have to fix in a hurry, like a production incident, for example.
I constantly have to push Claude to refactor code and extract pieces, not because the nesting is too deep or there is too many lines in a single function, but just to name things and give them meaning. LLMs tend to produce obscure code that doesn't aid understanding.
I view refactoring as steering the code in a particular direction. You have to know where you want to end up, or you'll wander aimlessly or end up somewhere else, making it harder to get things right. And each refactor is documentation of that journey.
I've seen this story many times, and most of them, these inefficiencies are kind of made up by the team not wanting to move. Generally, the UI team has good excuses related to Not-Built-Here, and the article provides precisely one such. Not saying Backend does not also have good excuses but
> They just need a simple model-view-controller architecture like PHP provides. Having pointers to memory addresses and managing concurrency via goroutines rather than just writing linear PHP that Apache runs in parallel is really much more than they bargained for
Is the kind that I've seen be the team's fault, with at least two instances of a guy going in and fixing the problem according to the new spec within three work days.
> Except maybe for the investment banking team. They really need their Erlang architecture for decentralized networking - after all, they process fast-moving market data, order execution, and the like.
I don't know... it seems to me that Go might actually be perfectly adequate for these workloads. The goroutine scheduler is a reliable way to handle concurrent market feeds AFAIK.
Go can also do MVC just as well as PHP. Hell, the standard library has net/http and html/template, or you can reach for Using gsx (or templ) and your UI components are just compiled Go functions.
I think the real problem in this scenario is that there's a bottleneck "platform" team. This takes the "dev" right out of devops.
I'm just not sure that "you can't do everything in golang and react" holds water. You can do pretty much anything in anything, these days.
DRY is supposed to be about reducing connascence, IMHO. You don't need a "platform" team to do that. You need transparency between teams so there's no duplicate effort. Something like a shared backlog.
Sometimes syntactic duplication can give you a hint to underlying semantic duplication. But it's no more than a hint.
DRY doesn't mean don't repeat a similar looking block of code, it means try to structure your code so that each element of the design has a single representation.
There's no shortcut to good design where no thinking is required, much as a lot of people seem to wish there were.
What do you mean, Claude just told me my architectural ideas were terrific and we're halfway through implementing a restructure of the company's codebase!
You know what they say. The first 50 percent of the restructure accounts for the first 50 percent of the development tokens. The remaining 50 percent of the restructure is approached asymptotically as tokens→∞.
Absolutely. The rule of thumb is that two things should be abstracted together iff they should change together. The down-sampling constant matching the upweighting factor? Don't repeat yourself. Needing a half-dozen subtly different circular buffer definitions? Circumstances vary, but repetition is probably fine. Two pieces of code which are literally identical? As you said, the syntactic duplication suggests there's an underlying semantic duplication you might want to iron out, but if the two callsites really want the potential for independent behavior then byte-for-byte code duplication can make more sense.
But, like the rest of software, even that's just a guideline. Suppose you've been painted into a corner where code needs to be synced between languages. There are solutions, but especially if it happens rarely then those solutions might be a lot more expensive than just a comment at both locations.
"Duplication is far cheaper than the wrong abstraction" - Sandi Metz[0]
[0] https://sandimetz.com/blog/2016/1/20/the-wrong-abstraction
"A little copying is better than a little dependency." -- Rob Pike
[0] https://go-proverbs.github.io/
[1] https://youtu.be/PAAkCSZUG1c?si=0gXCrQfAyxjCWOnT&t=572
It’s fun because microservices tend to evolve into both of those.
Won't disagree with that, that's why the rule of 2-3-4 is good, don't bother for 2 instances, consider if it really needs an abstraction at 3 times, at 4 it's probably time before things grow out of hand.
Because when you have 20+ repetitions you start needing buy-in for fixes because the testing needed might be beyond something simple.
Or as the go proverb goes "a little copying is better than a little dependency" (https://go-proverbs.github.io/)
We are exactly where the hypothetical bank is. Our large outer company gobbled up nine or ten smaller companies with disparate stacks (PHP, Haskell, C#, a few others). After a couple years of integrating through shared APIs, new management is trying to force us all into a single platform - Go and Node+React.
We have thousands of years of combined experience in our various technologies and we are to throw that away in the name of "unity" for a stack literally no one in the company was using but "it should be good for AI"
A bigger part of the positives of repeating yourself is that yourself is plural in this case and other people kind of suck and solving your own problems should be easy.
As an example, I put in a request with the platform team to set the UI toolkit to internal instead of private so it can be more easily accessed cross organization. I have been waiting like six months. No one knew who was in charge of it. ALL our repos have been mandated internal for years so our disparate orgs can read each others code. AFAIK we're the only team that actually lives up to it.
I am annoyed by the lot of it.
This sounds like a pretty fun project if you're actually allowed to use AI to automate most of the process.
Management WILL find out:
https://xkcd.com/927/
Adding their chosen be-all-end-all solutions is the easy bit. Removing existing parts from the tech stack, is the hard part.
(and of course "new" may not improve on "old" even if stuff is migrated successfully)
The upside: all this changing / migrating / implementing / testing gives you a job.
I was with them right up until the admonition against standardizing the UI components. This is not an all-or-nothing proposition. You build a standardized library incrementally, and you slowly migrate codebases over to use them. I've seen some pretty horrendous UI mish-mash in what should appear to be a single application, because each piece was done independently and then stitched together.
You end up with drifting implementations that may or may not come from the same root at different points, where the same fix has to be applied multiple times as each team learns the lessons for what not to do, etc. Effectively what DRY is about.
I got rid of about six years worth of technical debt on exactly this in our frontend last Friday. All it took was a few AI prompts. These types of issues are just melting away now.
Code duplication is fine as long the duplicates don't drift apart. Keeping them in sync is a bit tedious for people. And people tend to cut corners. So there's a potential to end up having to fix the same kinds of issues several times. But with AIs doing all the tedious work, staying on top of that is pretty doable. It's more a question of whether that's a good use of time and tokens. You could just make it fix things properly.
In the code base I mentioned, we had a few different component libraries that at some point were selected, used, and then later abandoned. We also had taken into use tailwind at some point but we never completed the upgrade to tailwind 4. And we had a bunch of manually styled html as well. It's an application with a lot of different functionality, lots of different screens, etc. So there was a bit of pressure to not break things. I fixed all of that in a few prompts. The application still looks and feels the same but is much more consistent in terms of look and feel (we had several varieties of buttons and input fields with subtly different behavior). We found and fixed a few minor issues since then.
reminds me of WET: Write Everything Twice. Instead of immediately jumping to DRY, actually write out the two similar tools, then see what actually makes sense to combine into a shared dependency.
I like HUMID "Hold off Until Many Instances of Duplication"
MOIST: "Mull Over Instances, Seek Third"
Two is a coincidence, three is a pattern.
DAMP: Do As Mf Please
MUD: Maybe... Uh, Dunno
SWAMPY
Software will always metastasise. Probably yeet!
Related: attributed to Ian Fleming:
"Once is happenstance, twice is coincidence, three times is enemy action."
Yes, writing it twice is the perfect way to figure out the right level of abstraction for your project, and how extensible your components need to be. Try to do it with only one instance in front of you, and you end up with all sorts of unnecessary abstractions "just in case".
If you find yourself writing it a third time, on the other hand, you should seriously start consolidating.
WET will always be "We enjoy typing!" to me.
Although in reality I wrote some things thrice before deciding to condense them and I considered it decently DRY.
my version of this is that, as it is getting closer to user perceived layer, use WET, as it move away from user preceveid layer and toward system level, use DRY.
I believe that's also called the Rule of Three.
https://en.wikipedia.org/wiki/Rule_of_three_(computer_progra...
I've always found DRY to be more useful when applied to data rather than code. Eg don't have two versions of an enum, or a mapping, or the information in some database.
In some cases DRY is also related to parse-don't-validate. Don't repeat validation all over, but have a single canonical parser and a single canonical data transfer object. Typescript frontend+backend makes this even easier.
What I'm missing here, is the security aspect. The author does mention that "there are capabilities, such as DevOps, that are best handled centrally", but I'd expect Mike the VP to put security in the platform team's responsibility, as well as in each team.
The sentiment is somewhat understandable, especially in the world of fast-moving AI-enabled companies all around us. The example doesn't really sound motivating out of the gate.
> All three teams adhered to the corporate branding guidelines, so their products look and feel reasonably similar. They also work fairly well and were shipped on time. This is the opposite of how things play out in most of the world's large companies, from any major bank to supposedly tech-savvy giants like Google. Every time you cross an app boundary or even a team boundary within a single product, all bets are off. At best, the UI differs in small, annoying ways (button styling, UI element rounding radii), or at worst, you need to go through separate login and payment flows.
> whenever the user switches from the account view to the investing tab, a whole new JS framework is loaded. But, given all other factors, this is an acceptable trade-off. I guess it's acceptable if you are going from one major product to another, but accepting this when switching between parts of an application that are supposed to be coherent (same banking app, same money involved) tells the customer that you don't care about their experience that much. Accepting this also massively increases the chances that the UX will be different, since frameworks tend to come with their own patterns that shape developer thinking.
Of course, it's OK to repeat yourself as many times as needed to keep shipping products that affect the bottom line of the business and help customers achieve more. At the same time, as a company transitions to multiple products or breaks up the monolith of its main product, it should also start building the DNA for maintaining a coherent UX. This is less about using the same technologies under the hood and more about crystallizing the foundational API shapes and packaging them in a way that allows teams to offer customers a consistent set of UX expectations across internal company boundaries.
In practice, this means that some choices have to be made in a BDFL-style fashion: one general-purpose OLTP database with a preferred way of interacting with it (ORM or not), one JS framework with components supporting shared data structures (with escape hatches for specialized use cases), and one opinionated design system covering the vast majority of use cases across the company's major products.
> there are capabilities, such as DevOps, that are best handled centrally
It's okay to say that you have an Ops team in 2026. If it's not DevOps then let's not call it that.
I thought this was ancestry.com and I was like "yeah repeat yourself by having kids i guess, thats kinda how ancestry works", why is this on hackernews?
Then I clicked and read and nodded a bunch.
Would have sworn it said ancestry.com
So, instead of DRY code we should have DRY code?
Even the DRY principle isn't a hard and fast rule, and in fact most experienced engineers will say that two copies of duplicate code shouldn't be "DRY-ed up". Most set the max at three copies, because "DRY-ing up" code before that point ends up being counter-productive.
Similarly here, except the author isn't talking about code, but systems made out of code. And they're not saying "don't get rid of repetition" ... they're just saying sometimes repetition serves a good purpose, so don't try to "DRY" everything up.
Well... remembering to ask "did you fix it everywhere?" is strictly harder than having only one place, if you don't introduce too much contortions to bring that about.
If.
It's a fairly old acronym replacement after everyone realized "don't repeat yourself" was like "premature optimization" - and misleading people. Nothing wrong with a little repetition and a perfect abstraction is likely a wasted investment. There was also "do repeat yourself twice" and "don't repeat yourself thrice" (on the third copy.. think about optimizing)
2009 Unit Testing - Do Repeat Yourself (8 points) https://news.ycombinator.com/item?id=819982
2016 DRY: Do Repeat Yourself (6 points, 6 comments) https://news.ycombinator.com/item?id=11805945
As I often like to say when DRY comes up, the fact is I've wasted way more time over the years fixing unforeseen bugs in abstraction layers than I would have making changes in two places sometimes. After a while you realise simple is usually better.
Ain't this the truth.
Personally, I've seen just as many bugs from two implementations drifting.
But conversely, with two implementations you can change one if needed without affecting the other.
I've had this happen a few times, you DRY an abstraction and then discover that the cases you thought were the same are slightly different. Now you have to add parameters or logic and change or at least test everything it touches.
this is my main point, yes.
N (initially) copied implementions does introduce the risk of 'forgot to update this one' bugs, but these bugs are about as simple as it gets to find and fix.
Abstractions on the other hand introduce the risk of 'what random thing am I going to break by changing this?' bugs which are typically much harder and more time consuming to find and fix. Further, the risk is recursive, as the fix might break yet another thing.
I'd maybe agree with the gp that instances of the former are as common as the latter. But to my original point, they just waste far less time.
I certainly know which class of bug I'd prefer to have to fix in a hurry, like a production incident, for example.
If you have good taste in abstractions, fixing a bad abstraction is usually just copy/paste/rename/modify.
An abstraction is not only for avoiding repetition; it's for gaining deeper insight into what you are actually doing.
I constantly have to push Claude to refactor code and extract pieces, not because the nesting is too deep or there is too many lines in a single function, but just to name things and give them meaning. LLMs tend to produce obscure code that doesn't aid understanding.
I view refactoring as steering the code in a particular direction. You have to know where you want to end up, or you'll wander aimlessly or end up somewhere else, making it harder to get things right. And each refactor is documentation of that journey.
I've seen this story many times, and most of them, these inefficiencies are kind of made up by the team not wanting to move. Generally, the UI team has good excuses related to Not-Built-Here, and the article provides precisely one such. Not saying Backend does not also have good excuses but
> They just need a simple model-view-controller architecture like PHP provides. Having pointers to memory addresses and managing concurrency via goroutines rather than just writing linear PHP that Apache runs in parallel is really much more than they bargained for
Is the kind that I've seen be the team's fault, with at least two instances of a guy going in and fixing the problem according to the new spec within three work days.
> Except maybe for the investment banking team. They really need their Erlang architecture for decentralized networking - after all, they process fast-moving market data, order execution, and the like.
I don't know... it seems to me that Go might actually be perfectly adequate for these workloads. The goroutine scheduler is a reliable way to handle concurrent market feeds AFAIK.
Go can also do MVC just as well as PHP. Hell, the standard library has net/http and html/template, or you can reach for Using gsx (or templ) and your UI components are just compiled Go functions.
I think the real problem in this scenario is that there's a bottleneck "platform" team. This takes the "dev" right out of devops.
I'm just not sure that "you can't do everything in golang and react" holds water. You can do pretty much anything in anything, these days.
DRY is supposed to be about reducing connascence, IMHO. You don't need a "platform" team to do that. You need transparency between teams so there's no duplicate effort. Something like a shared backlog.
first time I have seen someone mentioning connascence since my obsession into program design research.
I think about it all day every day as a professional programmer.
repetition is work, just because we can automate doesn’t mean we should avoid tedious work in favour of more fun but more inefficient work.
not many other disciplines have this issue, all trades workers like carpenters or welders just repeat and repeat