DRY = Don’t repeat yourself

You are viewing a single thread.
View all comments View context
4 points

The code in the article isn’t complicated enough that I’d bother. It even ends up with about the same number of lines of code, hinting that you probably haven’t simplified things much.

I think it’s a good example of the problem though. People take that same idea and apply it too liberally. The point isn’t that specific code, it’s about not apply DRY to code that’s coincidentally identical.

But otherwise, I disagree with the article. If it’s complicated enough to bother abstracting the logic, the worst that can happen in the above situation is that you just duplicate that whole class once you discover that it’s not the same. And if that never happens, you only have 1 copy to maintain.

That’s… Not at all true in practice. What often happens with these “DRY” abstractions when they’ve been improperly applied is you end up with an inheritance hierarchy or a crazy template or some other thing. You’re really lucky if you can just copy some code and find your way out of the weeds.

There are plenty of bad abstractions in the wild and novices applying DRY is a common source of them.

permalink
report
parent
reply
1 point

There are plenty of bad abstractions in the wild and novices applying DRY is a common source of them.

You’re both saying the same thing though. Novices aggressively apply DRY the moment a second bit of identical code appears, while experienced developers often wait for a third copy and then think about whether DRY fits.

That said, I think "don’t apply DRY too aggressively is the whole point of this discussion, and the person you’re replying to was kind of needlessly disagreeing.

permalink
report
parent
reply
1 point
*

You’re both saying the same thing though.

We’re not quite saying the same thing though because …

It’s not a 2 vs 3 issue. You can have an infinite number of instances of the same logic and it still not be a case for generalization because it’s not actually general … it’s just an infinitely large program. You can also have two copies of the same code that should be reduced because they are general (e.g. you have the exact same algorithm for generating a UUID copied into two different spots). If you’re thinking about it in terms of quantity you’re already doing it wrong.

It’s not fixable by “just” copying something.

Those two points are really important points.

permalink
report
parent
reply
1 point
*

If you’re thinking about it in terms of quantity you’re already doing it wrong.

You’re ignoring that simple principles make great guidelines for not overthinking things.

And you’re doing so in the context of an article about the dangers of overthinking things.

You’ve over thought an article about the dangers of overthinking, while alienating potential collaborators with a condescending tone.

You’re coming across like one of the rookies who need this warning.

Consider counting to three, before applying DRY. It works.

permalink
report
parent
reply

Programming

!programming@programming.dev

Create post

Welcome to the main community in programming.dev! Feel free to post anything relating to programming here!

Cross posting is strongly encouraged in the instance. If you feel your post or another person’s post makes sense in another community cross post into it.

Hope you enjoy the instance!

Rules

Rules

  • Follow the programming.dev instance rules
  • Keep content related to programming in some way
  • If you’re posting long videos try to add in some form of tldr for those who don’t want to watch videos

Wormhole

Follow the wormhole through a path of communities !webdev@programming.dev



Community stats

  • 2.3K

    Monthly active users

  • 971

    Posts

  • 8.7K

    Comments