Hacker News new | ask | show | jobs
by gnabgib 17 days ago
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

2 comments

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

If you have good taste in abstractions, fixing a bad abstraction is usually just copy/paste/rename/modify.
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.

Ain't this the truth.