Live data from Hacker News

DRY is an over-rated programming principle?

gordonc.bearblog.dev

61–70 of 501 posts

Re: DRY is an over-rated programming principle?

#62
post #56

I am working in a code base right now that was literally ruined because of #3. It's full of extremely difficult to follow and test higher order functions that are completely unnecessary. A feature request did come for a "half/half" pizza and we're spending our days trying to disentangle the higher order functions. The developer who wrote this thought himself the programmer genius and wanted to make a pattern out of e…

>"why did you hire this guy in the first place, or why did you not fire him?"

Because many companies are actually looking for these guys following the principles to a T initially. It's only midway through they complain about them lacking flexibility, if ever. Then later everyone complains about the incomprehensible mess while a few go "that's the way things are, we just need smarter people to understand our solutions".

And of course, it takes them 10 years to do something with a huge team which only took a small team a few years.

Re: DRY is an over-rated programming principle?

#63
The problem with DRY is that it doesn't tell you how many repetition is too many.

Here's my advice: don't refactor when you repeat yourself twice, refactor when repeat yourself _three_ times.

Having one chance to copy-paste before DRY'ing your code has been one of my most treasured coding tricks, it'll save you so much time and premature refactoring.

Re: DRY is an over-rated programming principle?

#64
post #56

I am working in a code base right now that was literally ruined because of #3. It's full of extremely difficult to follow and test higher order functions that are completely unnecessary. A feature request did come for a "half/half" pizza and we're spending our days trying to disentangle the higher order functions. The developer who wrote this thought himself the programmer genius and wanted to make a pattern out of e…

>Argument by Authority may be a fallacy, but it is significantly more persuasive than other arguments.

I looked at https://gordonc.bearblog.dev/ - I don't know why I would think this guy was any more of an authority on what was important than I am. So I'm not sure if anyone who thinks they're a programming genius would even care.

Re: DRY is an over-rated programming principle?

#65

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…

This. The clean code principles should be considered within the specific context of the situation. They are guidelines that are good to keep in mind, but no more than that. The article gets this wrong by considering DRY as some kind of dogma and then discovering some situations where it doesn't work well. And then of course some commenters here get it wrong by only looking at situations were it does work well. It's t…

> They are guidelines that are good to keep in mind, but no more than that.

How great dev life could be if everyone saw it like that.

Re: DRY is an over-rated programming principle?

#66
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…

TLDR: If you do DRY in moderation it’s great (as the OP explicitly says).

What's funny is that DRY was first popularised in the Pragmatic Programmer[0] book, and "coincidental" duplication is explicitly addressed right there on page 34, "not all code duplication is knowledge duplication... the code is the same but the knowledge is different... that's a coincidence, not a duplication."

[0] https://www.amazon.co.uk/Pragmatic-Programmer-journey-master...

Re: DRY is an over-rated programming principle?

#67
post #41
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…

> Mistake 1: Switch from DRY to premature optimization. "Premature optimization" is largely a bogus concept, because the meaning of "optimization" has shifted a lot since the concept was first created. People now use optimization to mean "sensible design that does not needlessly waste resources". In this meaning of optimization, "premature optimization" is a bogus concept. You should absolutely ALWAYS write non-pessi…

The reasoning behind discouraging premature optimization makes no distinction between "micro optimizations" and any other kind, the purpose of this guidance is to minimize wasting time building unnecessarily complex solutions based on untested performance assumptions.

Re: DRY is an over-rated programming principle?

#68
post #53

The one and only important programming principle: use your brain. Not every problem is the same and not every pattern could be used to solve every problem.

This true, but it is not very helpful advice for a novice programmer. DRY is popular because it is easy to follow. There are even tools which look for similar chunks of code in multiple places (and some companies put such checks in CI which IMO a bad idea).

Re: DRY is an over-rated programming principle?

#69
post #52

In this case, the problem is with a bug creeping in: crust: "thyn", DRY is about avoiding this class of cut-and-paste bugs too. Or with changing a string to a token, as it should have been: crust: THIN The code isn't even correct. It's mixing JavaScript and Python. I'm also not sure why you'd declare functions for each type of pizza; that's data. I'm not sure about the context, but the right way is: def make_pizza(cr…

Speaking about bugs, can you spot how he introduced a bug when going DRY? :) In case it gets fixed: https://i.imgur.com/ZR2XKA7.png

Or deliberate, as everybody knows that pineapple doesn't belong on pizzas :-)
Post reply on HN