this post was submitted on 20 Dec 2024
97 points (92.9% liked)

Programming

17677 readers
37 users here now

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



founded 2 years ago
MODERATORS
 

DRY = Don't repeat yourself

you are viewing a single comment's thread
view the rest of the comments
[โ€“] wccrawford@lemmy.world 14 points 6 days ago (7 children)

First off, I generally don't worry about DRY until there are 3 instances, not 2. With only 2, it's really easy to over-generalize or have a bad structure for the abstraction.

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.

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.

Yeah, I'm reminded of how Germanic languages used to have singular, dual and plural. If we'd still had dual, we'd probably also be talking about not abstracting until we actually have a plural.

load more comments (6 replies)