2
When DRY goes wrong (hackeryarn.com)
top 6 comments
sorted by: hot top controversial new old
[-] jboyens@beehaw.org 3 points 1 year ago

DRY is nice and all, but never let your code get so DRY it chafes.

[-] bh11235@infosec.pub 2 points 1 year ago

My tech niche is not a Big Shot Software Engineer(tm), so take my opinion with a grain of salt. Still, from my limited understanding, if in a very DRY project you get "brittle code where simple changes are scary because they could have a huge ripple effect", what would be the alternative experience you would get in a, uh, humid project? Instead of "ok this one change overhauls an implicit assumption in every single part of the program" you get "ok this one change overhauls an implicit assumption in some parts of the program, and some other parts of the code might be making another implicit assumption incompatible with the first, and hey maybe these parts overlap, who knows". Again, based on my limited understanding, trading the first scenario for the second does not seem that attractive a deal.

But really the true reason for my opinion is that once somewhere on the internet I saw someone oppose DRY principles using the slogan "Don't DRY yourself out", and the lame '90s PSA campaign energy inherent to that phrase infuriated me so much that I've supported DRY in software design ever since, out of pure spite. Behold -- man, the most rational of all animals

[-] steph@lemmy.clueware.org 1 points 1 year ago* (last edited 1 year ago)

The example is more of an issue with using the right tool for the job: using classes inheritance and overloading would properly deal with the employee/manager/c-suite distinction.

[-] hackeryarn@lemmy.world 1 points 1 year ago

For sure there are better abstractions that would help. I still think that they only help with over abstraction to a certain point. Digging 5 classes deep just to figure out what's actually happening is just as, if not more, frustrating than digging 5 functions deep.

[-] cyberdecker@beehaw.org 1 points 1 year ago

I often see this problem in the testing world, particularly around frontend tests that utilize UI automation tools.

The pattern I see is often to abstract chunks of common steps into individual functions that often live in places very disconnected from the test. While this might reduce the number of lines of code in a test and arguably make it more maintainable it has its problems.

Main problem number one is that readability has been diminished. It is now harder to understand exactly what this test is doing because steps have been abstracted away. Tests that can be clearly understood, read and describe functionality and behaviors are immensely important to getting others to quickly understand code. I hate to put a barrier there to making that happen.

Second, i don't truly believe it ALWAYS improves maintainability. This decision of abstracting carries a risk. When that abstraction needs to change in one place you are faced with a tough choice...

Does this need to change in ALL places? How do you know? How can you get all places it is used and be certain it has to change in all of them? Changing for all usages is RISKY particularly when there are large numbers of uses and you don't know what they all do.

Do i make a new abstraction? This is safer but now starts to create bloat. It will lead down paths of making future implementations trickier because there are now two things to choose from that are possibly slightly different.

For tests I'm not really convinced that these problems are worth dealing with. Keep it simple and understandable. Repeating yourself for the sake of clarity is okay. I'll say it again... Repeating yourself for the sake of clarity is okay!

[-] hackeryarn@lemmy.world 1 points 1 year ago

Yeah, I've seen this a ton. And it sucks because it's always done with good intentions.

That's why I think that if you need small helpers keep them short and prevent them from going too deep. Nothing is worse than digging through 10 layers of functions just to figure out what's going on.

this post was submitted on 11 Jun 2023
2 points (100.0% liked)

Programming

13250 readers
1 users here now

All things programming and coding related. Subcommunity of Technology.


This community's icon was made by Aaron Schneider, under the CC-BY-NC-SA 4.0 license.

founded 1 year ago
MODERATORS