News for hackers. Stuff that matters.
Re:DRY is an over-rated programming principle? by captainmuon on Thursday July 07, 2022 @07:25AM (#32012600)
Every time I read an article like this, "why <often cited best practice> is overrated", I think, yeah you are right in theory. But most places I have worked, these best practices were not overused, but underused. If you have the problem that your coworkers create unneccessary abstractions, I envy you, because I have so often had the opposite problem. Maybe this is not the case if you work in a great software development team. But if you work somewhere where they do software development on the side (science, hardware, etc..) it is the main issue.

People not able to factor out functions or structure their code in a readable way. Variables are called v1, v2, v3. Unit testing seen as a waste of time. CI seen as a fun toy. They lack the experience to even notice the difference.

Maybe I'm becoming a curmudgeon, but I think many people would be well served by just googling "<my programming language> best practices", learning the acronyms like DRY, and just following them. And when you have gained some experience, sure, then you should question the wisdom and not follow it blindly.

Re:DRY is an over-rated programming principle? by lowercased on Thursday July 07, 2022 @08:04AM (#32012933)
> People not able to factor out functions or structure their code in a readable way. Variables are called v1, v2, v3. Unit testing seen as a waste of time. CI seen as a fun toy. They lack the experience to even notice the difference.

Had a colleague work under a 'team lead'. Needed to take a form with variable amount of rows of input data - max 50 - and take data, parse it, and store it. Took 20-30 lines of code. Next day "I don't trust loops, these need to be unlooped". Really? This was all in writing and stated out loud in a meeting with witnesses, and everyone agreed. "Loops can be tricky - they don't always work like you think" (something like that). So a 30 line block of code with a loop around it became 1200+ lines with 'v1, v2, v3.... v50', with 'ifs' around each one to check if that row number was also submitted.

The code to generate the form was, of course, a loop that spat out holders for 50 rows. THAT was OK, because someone else's team wrote that a while back (really??) and ... it was already done and in production. The lead could not put their stamp on it.

Very very very weird. Having half a dozen other people all nod their head suggesting that a 30 line loop is fraught with danger, and the correct answer is copy/paste 50 times. Felt like gaslighting, to my recollection. Worked in same dept, just not on same project together, but enough of this was heard/pickedup across the dept.

And... my colleague and I aren't there any more, and to my knowledge, that team lead is still there.

Re:DRY is an over-rated programming principle? by cafard on Thursday July 07, 2022 @09:25AM (#32013782)
This is what I call "preloopsarian": a state of coding innocence in which one has discovered assignment and alternation, but not iteration.
Re:DRY is an over-rated programming principle? by wazoox on Thursday July 07, 2022 @09:38AM (#32013917)
Looks like straight out of https://thedailywtf.com/
Re:DRY is an over-rated programming principle? by an9n on Thursday July 07, 2022 @10:20AM (#32014460)
It's been a while since I'd visited! Always amusing.
Re:DRY is an over-rated programming principle? by JacobThreeThree on Thursday July 07, 2022 @10:45AM (#32014758)
>Felt like gaslighting, to my recollection.

Sounds like a real-life example of the Asch experiments.

https://en.wikipedia.org/wiki/Asch_conformity_experiments

Re:DRY is an over-rated programming principle? by ergonaught on Thursday July 07, 2022 @08:42AM (#32013300)
That's terrible.

I was in a situation in the early 2000s where the team that would maintain our application after we were gone (to another project or product or company) were not skilled enough to follow certain things, and we were asked to change a number of things to make it easier for them. In that case, the leader of their team was self-aware and honest and communicative, which is the rare and exotic thing, but we did have to re-architect some things and even change the programming language in one area to suit their capabilities. Sometimes that's a business need, and it matters.

Re:DRY is an over-rated programming principle? by anarazel on Thursday July 07, 2022 @12:47PM (#32016325)
At the very least it's a signal to hurriedly look for a new job, if not resign on the spot.
Re:DRY is an over-rated programming principle? by thekiptxt on Thursday July 07, 2022 @12:07PM (#32015787)
One time I needed to sort some data arbitrarily — the resulting order did not matter, it only mattered that it was the same for the same data in different orders.

My senior engineer advised me against using Java .sort() because “we didn’t write it so we couldn’t be sure it would do the same thing every time.”

Re:DRY is an over-rated programming principle? by Banana699 on Thursday July 07, 2022 @01:34PM (#32016924)
To play the fun game of charitability, that engineer could have been talking about sort stability. Which could technically violate the property you want.

A quick search however does say that Java's .sort() is stable.

Re:DRY is an over-rated programming principle? by amcpu on Thursday July 07, 2022 @08:53AM (#32013437)
Sounds like something out of https://blog.codinghorror.com ! :)
Re:DRY is an over-rated programming principle? by dfee on Thursday July 07, 2022 @10:01AM (#32014216)
I regularly see code of the form `if(x == false)` as the author has a distrust of `if(!x)`.

I guess the author just distrusts smaller things, leaving me to distrust the author’s larger things.

Re:DRY is an over-rated programming principle? by ickyforce on Thursday July 07, 2022 @10:37AM (#32014670)
This is completely another level of "issues" than other problems in this thread. During code review I'd only mention it as a nit. The longer form is correct and the only downside is that's a bit longer. It doesn't mess up code modularity or affect maintainability in a noticeable way.

Well, assuming that the language doesn't have any quirks in this area - e.g. in Java your statements aren't equivalent for a Boolean x.

Re:DRY is an over-rated programming principle? by kaba0 on Saturday July 09, 2022 @03:02AM (#32032586)
Nitpick (as in general you are right regarding java as well): I’m fairly sure they are the same for java in this instance. Both will convert Boolean to boolean, throwing an NPE if it was a null.
Re:DRY is an over-rated programming principle? by ickyforce on Saturday July 09, 2022 @08:38AM (#32034483)
Ha, that's true, thanks! I guess my Java-fu is weak these days :)
Re:DRY is an over-rated programming principle? by wizofaus on Thursday July 07, 2022 @03:47PM (#32018462)
They're not equivalent in many languages (JS, C++/swift with operator overloads, if x is nullable etc. etc.).
Re:DRY is an over-rated programming principle? by khalladay on Thursday July 07, 2022 @10:37AM (#32014677)
It's been awhile since I absorbed the weird programming norm that "real programmers use the !x form!" but even after 10+ years of !x , I still find ==false more readable.
Re:DRY is an over-rated programming principle? by mcbutterbunz on Thursday July 07, 2022 @12:29PM (#32016066)
I agree. To me, its simpler to understand. Suppose x is a bool, reading the code, I say to myself "if not true..." or "if not false..." and my ape brain gets confused on what happens if its not true or not false.

Reading "if true == false" or "if false == false", it becomes much clearer what we're testing here and I understand it instantly.

Re:DRY is an over-rated programming principle? by linknoid on Thursday July 07, 2022 @03:16PM (#32018096)
If the statement is "if (!isGreen)", it's much clearer to say "if is not green" than it is to say "if is green is false". Putting == true or == false makes you convert a clear statement "is green" into "true" or "false" instead of just being a natural English statement. It would be like saying in conversation, "I want to go to the store is false" instead of "I don't want to go to the store".
Re:DRY is an over-rated programming principle? by kcartlidge on Thursday July 07, 2022 @05:17PM (#32019572)
> If the statement is "if (!isGreen)", it's much clearer to say "if is not green" than it is to say "if is green is false"

I agree that when you read it, it's clearer. And yet I still prefer "if(isGreen == false)" for reasons of clarity in another sense.

The "!" being right next to the "(" makes it easier to miss the "!" when scanning quickly through the code, hence reading the logic the wrong way round and seeing "(isGreen" instead of "(!isGreen". And that's enough of a risk to ignore the readability advantage of "(!".

(Edit: To be clear, I don't suggest "== true" for the opposite cases, as the lack of a "!" in those means the risk is gone)

Re:DRY is an over-rated programming principle? by godshatter on Thursday July 07, 2022 @06:59PM (#32020745)
It also helps readability if the ! is before a function name that doesn't follow the right naming convention for it. One of my pet peeves in C is "if (!strcmp(a, b))". "!strcmp" I read as "not string compare" and I would expect it to mean that the strings don't compare when it means the exact opposite. This is true of anything following the "0 means success, anything else is an error condition" error handling scheme. So I use "if (strcmp(a, b) == 0)" instead because the "==" makes look at what value it's being compared to specifically and I make fewer assumptions.
Re:DRY is an over-rated programming principle? by Banana699 on Thursday July 07, 2022 @01:37PM (#32016959)
Even if the not operator in the language you're writing in happens to be the actual word 'not' ?
Re:DRY is an over-rated programming principle? by khalladay on Sunday July 10, 2022 @12:28AM (#32041876)
My whole career has been C++ and shader languages, so this really hasn't come up for me. I imagine it being a real word would improve readability greatly.
Re:DRY is an over-rated programming principle? by xorcist on Thursday July 07, 2022 @03:54PM (#32018547)
Even more common seems to be

  if (x == true)
which always seem to come with some argument how it is "more clear".

I have started to ask people straight away to change to

  if ((x == true) == true)
which following the same argument should be even more clear.
Re:DRY is an over-rated programming principle? by recursive on Thursday July 07, 2022 @03:15PM (#32018081)
I wrote code like that sometimes. Equaling false is more specific, depending on language. There are many falsey things that are not false themselves.
Re:DRY is an over-rated programming principle? by cozzyd on Thursday July 07, 2022 @11:15AM (#32015147)
In some languages these do different things, right? (Or if someone did something horrendous with operator overloading)
Re:DRY is an over-rated programming principle? by mmcgaha on Thursday July 07, 2022 @11:17AM (#32015181)
As much as people push the more succinct if(x)/if(!x) style of expression, I don't know that it is better. Now if your example was if(is_a_thing) then maybe it reads better. Add to that the possibility of three value logic and I could lean more to the if(x == false) style.
Re:DRY is an over-rated programming principle? by BurningFrog on Thursday July 07, 2022 @11:10AM (#32015096)
The worst one is "if x=true", which to me says the writer doesn't know what the if statement does...

That said, if x is data read from elsewhere that just happens to be boolean, I can write code like that in Python.

Re:DRY is an over-rated programming principle? by pkamb on Thursday July 07, 2022 @04:23PM (#32018842)
The UW intro CS courses call the `if (x)` form "Boolean Zen", which I've always enjoyed.
Re:DRY is an over-rated programming principle? by sodapopcan on Thursday July 07, 2022 @03:13PM (#32018049)
I've seen this in Ruby and Elixir that drives me a little nuts:

  if !is_nil(foo)
Re:DRY is an over-rated programming principle? by lolc on Thursday July 07, 2022 @06:24PM (#32020358)
While it may not matter in many circumstances, this is not the same as "if foo", because false is not nil.
Re:DRY is an over-rated programming principle? by sodapopcan on Wednesday July 13, 2022 @10:21AM (#32083144)
It's true but in 10+ years of writing Ruby it hasn't mattered in _any_ circumstances I've come across. I also assert that having a boolean where `nil` is meaningfully different than `false` is a smell and should be avoided.
Re:DRY is an over-rated programming principle? by jon_richards on Thursday July 07, 2022 @11:24AM (#32015275)
Some of that might be Python habits which is terrifying for completely different reasons.
Re:DRY is an over-rated programming principle? by mmcnl on Thursday July 07, 2022 @03:35PM (#32018336)
!x is not equal to === false.
Re:DRY is an over-rated programming principle? by bigtunacan on Thursday July 07, 2022 @11:54AM (#32015629)
It's not usually needed (especially these days), but there are times that it is better to repeat every possible iteration by hand and not have a loop.

This is a technique called loop unrolling. It is done for performance reasons. This is something we used to do at a company working on games for the old feature phones (think Nokia 30/40/60 series stuff). The devices were very limited, there is no direct control over J2ME garbage collection, etc... so loops could very noticeably slow down games.

We initially wrote code with loops, then would performance test and manually unroll when it was necessary. Eventually this became very burdensome and we eventually... wrote code to unroll the loops for us and that code of course had loops in it because it was build code that wouldn't ship.

There are other performance situations where this technique applies.

This may not have been the situation there, but I think it's important that rather than assume stupidity from the outside that we try to ask why.

Re:DRY is an over-rated programming principle? by 988747 on Thursday July 07, 2022 @12:16PM (#32015892)
Loop unrolling seems like something that should be done by a compiler when you turn on aggressive optimization flags, and not something you need to code explicitly.
Re:DRY is an over-rated programming principle? by HWR_14 on Thursday July 07, 2022 @12:28PM (#32016058)
Now, that's probably true. However, in the days of feature phones compilers auto optimization were still inferior to a person unrolling a loop in ASM.
Re:DRY is an over-rated programming principle? by bigtunacan on Thursday July 07, 2022 @03:47PM (#32018452)
That is why I said it's usually not needed, "especially these days". This was not true at the time. Relying on primitive compilers, especially the likes of the J2ME garbage collection would lead to total freezes in a game from something as simple as a loop. As the garbage collector decides previous passes in the loop are no longer needed it can trigger a garbage collection sweep. With such a slow and limited device a garbage collection sweep would literally cause a game to freeze until the sweep completed which could take on the order of several seconds.

The loop unrolling was just one example of how we would go about preventing an undesirable sweep.

As another example a large global game object array would be created when a game was started. As objects were created and deleted they would really just update pre-created objects in that array.

This allowed us to prevent garbage collection, while simultaneously making sure we didn't run out of memory.

The Nokia 1618 (a series 40 device) has a heap limit of 1024KB. Many S20 and S30 devices were even further memory constrained.

Re:DRY is an over-rated programming principle? by layer8 on Thursday July 07, 2022 @09:37AM (#32013906)
> my colleague and I aren't there any more

The only right choice in that situation.

Re:DRY is an over-rated programming principle? by BurningFrog on Thursday July 07, 2022 @11:07AM (#32015048)
At one of my earliest jobs, in a previous century, if statements were introduced to the language (RPG-3).

I was delighted, but the old-timers were quite suspicious of this experimental technology.

Re:DRY is an over-rated programming principle? by avgcorrection on Thursday July 07, 2022 @03:48PM (#32018465)
That’s some did-I-wake-up-in-another-dimension shit. :)
Re:DRY is an over-rated programming principle? by akavel on Thursday July 07, 2022 @08:24AM (#32013100)
Makes me think I should consider myself lucky that so much time has passed since last time when something reminded me of https://thedailywtf.com...
Re:DRY is an over-rated programming principle? by parsadotsh on Thursday July 07, 2022 @08:12AM (#32012996)
This is terrifying.
Re:DRY is an over-rated programming principle? by lamontcg on Thursday July 07, 2022 @10:37AM (#32014672)
with people like that roaming around the landscape maybe there is a point to all that leetcoding nonsense, since they'll certainly spout off some truly insane stuff in interviews...
Re:DRY is an over-rated programming principle? by awestroke on Thursday July 07, 2022 @08:21AM (#32013075)
Which country was this in?
Re:DRY is an over-rated programming principle? by zasdffaa on Thursday July 07, 2022 @08:55AM (#32013454)
Elbonia perhaps?
Re:DRY is an over-rated programming principle? by lowercased on Thursday July 07, 2022 @07:10PM (#32020851)
US of A.

FWIW this was... 2005-ish.

Re:DRY is an over-rated programming principle? by nevinera on Thursday July 07, 2022 @08:44AM (#32013326)
In rails shops, "dry" is _always_ overused. It was part of the red->green cycle in TDD culture, and got mentioned in every context, and as a result nearly all legacy rails apps are filled with weird abstractions introduced in a commit with a message like "dry it up". The problem is that it's phrased as a rule rather than a smell.

DRY deserves to be listed with other code smells that may indicate a missing abstraction (and there are many), but there is never a reason to blindly extract chunks of code based purely on repetition. That's not a "first step toward good programming", it's a step in the wrong direction.

Re:DRY is an over-rated programming principle? by ahallock on Thursday July 07, 2022 @09:40AM (#32013945)
I've experienced this first-hand in a Rails app, last week in fact. The result was a messy, hard-to-understand hierarchy of classes and abstractions--just because two workflows shared some similarities. Usually I find this happening with hardcore OO programmers or bored programmers who feel the need to start creating and don't know when to stop. I prefer boring code at this stage in my career.
Re:DRY is an over-rated programming principle? by ParetoOptimal on Thursday July 07, 2022 @11:30AM (#32015351)
> just because two workflows shared some similarities. Usually I find this happening with hardcore OO programmers or bored programmers who feel the need to start creating and don't know when to stop. I prefer boring code at this stage in my career.

As a Haskeller, when I do this it's about getting certain guarantees about the semantics of related workflows and knowing they must behave the same in X, Y, and Z.

This aids in reasoning about inevitable production issues.

I find boring code easy to modify but hard to reason about from a higher level and that it typically requires nastier solutions to maintain backwards compatibility.

That last point is contradicted by this posts example though, so it has me reflecting on things.

Re:DRY is an over-rated programming principle? by michaelcampbell on Thursday July 07, 2022 @10:14AM (#32014380)
Thanks; this is about what I was going to say but you said it better.

DRY is a tool, not a design goal. I think part of the Rails issue is a combination of the early Rails hype/philosophy, and the fact that DRY as a concept is so easy to "get", that everyone gets it but often fail the next step of "why". Without the why, you often can't figure out the right when/where so it gets applied everywhere.

It feels to me like another oblique angle of Goodhart's Law; eg: "A rule of thumb that becomes a required practice ceases to be a good rule of thumb".

Re:DRY is an over-rated programming principle? by harry-wood on Thursday July 07, 2022 @12:24PM (#32015996)
But "early Rails hype/philosophy" is the only thing you've said specifically about Rails. I think I know what you mean though. There are strong philosophies in the Rails (and more generally ruby) communities. Opinionated coding, and software craftsmanship is lauded, more than in other language communities I think.

As a result, rules of thumb like DRY are drummed into new developers. The overall effect of that is probably better code quality in general, but yes probably more instances of them being over-used.

But if Rails has the problem of folks over-using DRY, what are other languages communities doing? Just not doing so well at telling people about DRY in the first place?

Re:DRY is an over-rated programming principle? by codesnik on Thursday July 07, 2022 @08:04AM (#32012928)
I sometimes use term "mid-level engineer syndrome", for "too many levels of abstraction in the codebase". It is very common in my experience. And untangling it's usually harder then extracting common stuff from "dumb" code. I usually don't DRY things up until three repetitions. And in test code - try to not DRY at all, copypaste is a friend of readable and mantainable specs.
Re:DRY is an over-rated programming principle? by scambier on Thursday July 07, 2022 @09:37AM (#32013916)
I have colleagues that take DRY to an extreme when it comes to tests. There are so many levels of abstractions that it's incomprehensible. Tests should be clear and readable, you shouldn't have to dig code to understand _what_ a test is doing.
Re:DRY is an over-rated programming principle? by michaelcampbell on Thursday July 07, 2022 @10:17AM (#32014414)
Tests in particular SHOULDN'T be DRY, IMO. They need to be very much independently modifiable quickly; they're meant to be quirky end-runs around your bespoke, artisinal architecture to get at all the interesting bits. Repetition there is fine.
Re:DRY is an over-rated programming principle? by bcrosby95 on Thursday July 07, 2022 @12:55PM (#32016415)
I dunno. I think a few helper methods helps a lot in tests - like if you have a common operation in the setup portion. I don't think the code needs to be super abstract, but it shouldn't all be hand typed out.
Re:DRY is an over-rated programming principle? by baobabKoodaa on Thursday July 07, 2022 @12:43PM (#32016271)
A downside of this approach is that sometimes when you make a small implementation change, you need to rewrite 50 unit tests.
Re:DRY is an over-rated programming principle? by kosmotaur on Thursday July 07, 2022 @10:51AM (#32014855)
> copypaste is a friend of readable and mantainable specs

Another generic statement: copypaste (as I understand you mean the opposite of extracting common code) between specs goes against single responsibility. Rather than `setupUser()` you open a connection, create a user fixture, write it to the db, and then paste that across all the specs. Doing quite a lot.

I can imagine a spec with let's say 20 cases. Arrangement of each takes about 6 lines to load something, change some state the test subject depends on, the usual stuff, like in the above example.

A week from now, 10 cases need an extra line of setup, which you dutifully paste across the specs which require them. You put it somewhere in the middle, as it needs an id from the first step of 6.

This happens once or twice. The commonality of the original 6 copy pasted all over the place is hashed up, interspersed with calls specific to each test. The linking factor between those 6 lines is now obscured and requiring careful analysis if only those 6 need to change.

This can be avoided if you extract the common bits out early on. Rule of three is your friend if you don't want to rush it.

Re:DRY is an over-rated programming principle? by CTmystery on Thursday July 07, 2022 @08:55AM (#32013457)
You're almost there, IMO. This internet stranger encourages you to ditch the rule of DRYing based on the number of repetitions at all, and instead think of DRYing based on what deserves to change to together. Sometimes a single repetition in code deserves to be DRY. Sometimes 10 repetitions don't deserve to be DRY.
Re:DRY is an over-rated programming principle? by ryathal on Thursday July 07, 2022 @09:11AM (#32013635)
Isn't that playing a little loose with definitions? if you have 10 "repetitions" that don't need to change simultaneously they aren't really repetitions in the first place. Just because a dumb analyzer says you have a 10 line block of identical code in 10 places doesn't mean it's actually identical.
Re:DRY is an over-rated programming principle? by sirmarksalot on Thursday July 07, 2022 @04:54PM (#32019260)
You're restating the article's point. Naive DRY says make the dumb analyzer happy by abstracting out the coincidental similarities. If you work in a place that recognizes that this can be a red herring, then great, but a lot of developers and teams don't make room for that nuance. That is what the article is arguing against.
Re:DRY is an over-rated programming principle? by WorldMaker on Thursday July 07, 2022 @01:00PM (#32016477)
I'm a big proponent for the "rule of [at least] three" for building DRY abstractions: once is YAGNI (you aren't going to need it), twice is coincidence, three is finally a pattern emerging.
Re:DRY is an over-rated programming principle? by QuadmasterXLII on Thursday July 07, 2022 @07:34AM (#32012665)
In my workspace, the issue isn’t that junior developers consistently DRY too much or too little, instead they make dramatic mistakes in both directions. However, the code that repeats itself unnecessarily is way, way easier to fix than the code that tangles itself up like the left pineapple example.
Re:DRY is an over-rated programming principle? by kevstev on Thursday July 07, 2022 @11:31AM (#32015361)
> But if you work somewhere where they do software development on the side (science, hardware, etc..) it is the main issue

I have seen this working in finance. I worked at a startup with a quant, and my job became waiting for him to go home at 6 so I could clean up his code and make it maintainable the next day. Now I don't blame him- his background was operations research and he was a professor prior, without any real software background. But, he would get legit mad at me for messing with his code. We had a really tense relationship for awhile. I would occasionally break things, but he didn't really have tests until much later, so it was hard to detect and there were often subtle side effects.

But anyway, I think for awhile he thought I was just a pain in the ass, until one day about 9 months after we started the project, and he wanted to run some experiments using a specific universe of securities, and just apply a few constraints to them, and I set this up for him in about 5 lines of code, and all of a sudden, I could just see the light bulb finally turn on for him as to why I was doing all of these things. After that day we became a lot more friendly.

Re:DRY is an over-rated programming principle? by davewritescode on Thursday July 07, 2022 @07:38AM (#32012691)
Your problem isn’t DRY, your problem is that you don’t have people advocating for very basic best practices.

You can’t adopt DRY or SPOT or anything else if you aren’t free to refactor and you aren’t free to refactor without some tests.

Re:DRY is an over-rated programming principle? by kareemsabri on Thursday July 07, 2022 @08:30AM (#32013156)
In places I've worked DRY is overused, or used poorly. I can't count the number of times you get "DRY" on a code review just cause something appears twice. It's probably because it's the easiest one to spot.

> learning the acronyms like DRY, and just following them

Following DRY is the hard part. As the author points out, to DRY something up you need to pick the right level of abstraction. This requires experience to do well.

Re:DRY is an over-rated programming principle? by drewcoo on Thursday July 07, 2022 @02:49PM (#32017775)
It seems like your team should check for DRYness with a static analyzer like PMD. Your reviewers have better things to look at.
Re:DRY is an over-rated programming principle? by ARandumGuy on Thursday July 07, 2022 @11:07AM (#32015053)
This article is acting like DRY means "never repeat yourself in any circumstance". And it's easy to come up with counter-examples if that's your starting point.

While there are certainly some DRY proponents that treat it like that, most discussions I've seen advocating for DRY treat it as a rule of thumb. There are always exceptions, but DRY will steer you in the right direction more often then not.

Re:DRY is an over-rated programming principle? by dkarl on Thursday July 07, 2022 @01:49PM (#32017106)
> If you have the problem that your coworkers create unnecessary abstractions, I envy you

I'm curious what languages and frameworks you work with. I suspect this is something that varies from one programming subculture to another. In my experience, the only codebases where I've consistently seen underuse of abstraction have been PHP and C, and in those cases it has been because the code was written by entrepreneurs or engineers who were not software professionals. In Java and Scala I've seen plenty of code that used too much abstraction but almost no code that used too little. In C++ and Python I've seen it go both ways.

In my book, what programmers need first of all is the willingness to rewrite their code. I've been trying to hit the right balance for twenty years, but even now I frequently have to backtrack because the decision to add or not add a layer of abstraction turns out to be wrong. Biasing somebody towards or away from abstraction just changes the kinds of mistakes they make without making them better at cleaning them up.

Re:DRY is an over-rated programming principle? by mmcnl on Thursday July 07, 2022 @03:34PM (#32018314)
I half agree here. Especially in Python applications, so often you so a class that is instantiated only once. I'm not sure if this is overly usage of OOP or DRY, but defining a whole class just to be instantiated once seems like a very verbose abstraction to me. There's nothing wrong with a few functions to group code together and leave it at that.
Re:DRY is an over-rated programming principle? by AnimalMuppet on Thursday July 07, 2022 @02:17PM (#32017440)
Every best practice can be overused - used where not needed, used where it doesn't fit, used in trivial cases. And if you've got people who haven't developed sound engineering judgment yet, they'll start by not using those practices. But once you convince them that they should, they'll use them everywhere, even the wrong places.

This is why best practices are needed, and why they are over-rated. Where they are used, they are often over-used.

Re:DRY is an over-rated programming principle? by surement on Thursday July 07, 2022 @01:02PM (#32016513)
> But most places I have worked, these best practices were not overused, but underused

For what it's worth, 90% of the code bases I've worked on overused DRY. Two pieces of code that do the same thing but that shouldn't be coupled should be repeated, otherwise you end up with a million "if" statements for all the separate cases this code will need to handle as it grows, as well as uncertainty about whether changes will have unintended consequences.

Re:DRY is an over-rated programming principle? by saltsucker on Thursday July 07, 2022 @12:38PM (#32016191)
I am a CS graduate working at a top HW company and you could not have stated it more perfectly. The code I have to work with given to me written by HW engineers is pretty brutal. Talking 1k+ lines of code with 5+ nested conditions on the reg. Ofc, no unit tests. Blows my mind.
Re:DRY is an over-rated programming principle? by galaxyLogic on Thursday July 07, 2022 @11:25AM (#32015282)
True b ut it's still good and fun to discuss whether the best practices could be improved even further. And usually they can because they are context-dependent. There are no absolute rules, except those imposed by the compiler.
Re:DRY is an over-rated programming principle? by theptip on Thursday July 07, 2022 @12:27PM (#32016054)
Yep, it’s a general gripe with thought-pieces; advice is context dependent.

Or, put differently, my HN motto: don’t give uni-directional advice when optimizing a U-shaped error function.