this post was submitted on 20 Dec 2024
92 points (92.6% liked)

Programming

17668 readers
201 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 [email protected]



founded 2 years ago
MODERATORS
92
Don't DRY Your Code Prematurely (testing.googleblog.com)
submitted 2 days ago* (last edited 1 day ago) by [email protected] to c/[email protected]
 

DRY = Don't repeat yourself

you are viewing a single comment's thread
view the rest of the comments
[โ€“] [email protected] 12 points 2 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.

[โ€“] [email protected] 1 points 1 day ago

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)