Live data from Hacker News

DRY is an over-rated programming principle?

gordonc.bearblog.dev

131–140 of 501 posts

Re: DRY is an over-rated programming principle?

#131
post #13

> Instead of our code being architected around the concept of how pizzas are made in the abstract, its architecture is tightly coupled to the specific needs of these two pizzas that we happened to be dealing with. The chance that we will be putting this code back the way it was is extremely high. Mistake 1: Switch from DRY to premature optimization. > You might think that legit reasonable developers but would not act…

I don't read coding opinion articles like OP but I like to check out comments. > DRY does NOT lead to over-complicating things. That is not true. I dive around foreign code bases a lot and dry-ness is actually a significant complicating factor in understanding code, because you're jumping around a lot (as in physically to different files or just a few screens away in the same file). As in, inherently every time it's…

aka

Abstractions have non zero complexity costs.

And

Repeated code has non zero complexity costs

Why is this a hard concept?

It doesn't make dry any less valid.

Generally you can invoke both reasons to do something but the underlying reasoning is always complexity.

Re: DRY is an over-rated programming principle?

#132
Despite the backlash in the comments, I have to say I agree with the article. I realized eventually that it's our job to produce solutions, and not write code. Engineering (at least for software) is about making a computer do something novel, or if not that then making easy to adapt. Creating code that is nice and elegant, DRY, is about engineering code, but not engineering a solution. If it helps make things easier then sure, but despite the simplicity of the examples I think they demonstrate what everyone has seen -- this one nice to have function or whatever turning really ugly from trying to handle all of the edge cases. At that point it becomes nice to not have, but it's too late.

Also, I liked the comment from ihateolives somewhere in the thread a lot.

Re: DRY is an over-rated programming principle?

#133
Premature generalisation is the second cousin of all evil.

The problem with DRY is that the cost of it being wrong in the future often isn’t accounted for.

Copy, paste, search, replace is underrated.

That said, it’s a balancing act. The right generalisations are great.

Re: DRY is an over-rated programming principle?

#134

Earlier quoted context omitted.

I don't read coding opinion articles like OP but I like to check out comments. > DRY does NOT lead to over-complicating things. That is not true. I dive around foreign code bases a lot and dry-ness is actually a significant complicating factor in understanding code, because you're jumping around a lot (as in physically to different files or just a few screens away in the same file). As in, inherently every time it's…

I can't disagree more. DRY forces you to create pure reusable code, and split your code into small pieces. When I read such code I need to understand just a few pieces.

It also leads to overengineered framework code that only exists to support the glue code that is now required to pull distant code together.

Increasing the distance between inputs and outputs increases complexity.

Reusable code isn't all that reausable when nobody understands it or things are so fragmented people can't figure out how to operate the code base.

This isn't a rule. It's a moderation thing.

Re: DRY is an over-rated programming principle?

#137
As anything it is just a tool in our toolbelt and should be used carefully. If our system contains same user validation in 2 places, changing it in 1 place may lead to issues, which are difficult to discover. However forcefully implementing DRY everywhere can lead to coupling and lack of separation between modules and influence deployments, and work of different teams. Its more difficult to build context of the implementation, if one needs to jump from file to file. There’s a balance to when to use it or not.

Re: DRY is an over-rated programming principle?

#138

Not sure why this is on the frontpage. Not only are there a bunch of typos, a bunch of code doesn't actually work the way they said it does. Also gotta love hating on the 10x developer or whatever for saying you are wrong. EVERYTHING HAS TRADEOFFS. Every single thing has tradeoffs. Obviously you should not write terrible, brittle code. The reason DRY is important is because when you start duplicating code, having 30…

Completely agree. This is a low quality blog post.

Re: DRY is an over-rated programming principle?

#140
post #133

Premature generalisation is the second cousin of all evil. The problem with DRY is that the cost of it being wrong in the future often isn’t accounted for. Copy, paste, search, replace is underrated. That said, it’s a balancing act. The right generalisations are great.

Search, replace it with a single call to unified method when there are more than enough repetitions in the code.

Probably people just call it 'Refactor'.

The requirement changes and you refactor it to meet requirement.

And that's all you need to do to avoid premature generalisation.

Post reply on HN