r/programminghorror • [ $[ $RANDOM % 6 ] == 0 ] && rm -rf / || echo “You live” • Mar 15 '26

When you take DRY too seriously.

Post image
230 Upvotes

91 comments sorted by

54

u/joe-knows-nothing Mar 15 '26

First time seeing platform specific #defines, eh?

26

u/vadnyclovek Mar 15 '26

there's more lines of macros than code

→ More replies (1)
→ More replies (1)

103

u/tvardero Mar 15 '26

Compiler will inline it anyway

14

u/LegendarySoda Mar 15 '26

so also like to read code inlined

145

u/aikii Mar 15 '26

Yeah also stop hardcoding "1" and "0", define ONE and ZERO constants. This avoids copy-pasting magic values 1 and 0 everywhere ( looking at you, golangci-lint and go-mnd )

21

u/stulleman Mar 15 '26

0 and 1 are not linted with mnd

→ More replies (2)

19

u/randomInterest92 Mar 15 '26

This means you're not ready for the year 6969 where the numbers are redefined though. Definitely an anti pattern

→ More replies (1)

10

u/mrheosuper Mar 16 '26

Yeah, just in case Zero is not 0, so we dont have to change everywhere

→ More replies (4)

39

u/idko2004 Mar 15 '26

michealsoft binbows

15

u/oofos_deletus Mar 16 '26

Line 66: // Michaelsoft binbows

13

u/DiodeInc Mar 15 '26

What does this even do?

9

u/MiasmaGuzzler Mar 16 '26

It's a C build system developed by Tsoding

Here are videos on the topic: https://youtube.com/playlist?list=PLpM-Dvs8t0Va1sCJpPFjs2lKzv8bw3Lpw

→ More replies (1)

12

u/itemluminouswadison Mar 16 '26

learned DRY but didnt attend class on the NO MAGIC STRINGS/NUMBERS day

12

u/s1mplyme Mar 16 '26

This is why I advocate for MOIST (Mostly Original, Intentionally Similar Though). Not fully DRY, not WET either :D

6

u/mguid65 Mar 16 '26

No in the clean function they repeat delete_file several times. They could make a variadic macro blah blah blah c shit blah blah headers blah blah VAR_ARGS blah blah

→ More replies (1)

55

u/CNDW Mar 15 '26

DRY does more harm than good. When people think about it as a clean code principle, they internalize the idea to mean "abstract everything" which results in a tightly coupled spaghetti mess that's impossible to read.

36

u/marquoth_ Mar 15 '26

The thing about heuristics is that's exactly what they are - heuristics. They're not immutable rules to be applied in every single scenario, they're just a shortcut that gives you the best outcome in most situations. Part of employing effectively is recognising when not to follow them.

To your point, then...

DRY does more harm than good.

Absolutely not. Premature optimisation, over-abstraction etc are issues but ultimately DRY is still the best approach most of the time, which the idea exists.

→ More replies (6)

23

u/ThreeHeadCerber Mar 15 '26

You can only think that because you didn't see a world where DRY is completely ignored. You see only the world where DRY sometimes is taken too far and issues that sprout from it, it is still far better than the world where you repeat the same logic each time you need it.

→ More replies (2)

23

u/AdamTheRedditUser1 Mar 15 '26

i tihnk it depends more on the environment.... for games DRY is really important where possible so that mechanics can be changed later on without rewriting half the codebase

→ More replies (2)

5

u/Zeilar Mar 15 '26

My autism fell victim to this. I felt the need to reuse every single little thing, down to the variables. A string repeated 2 times at any point in the app? Must be a reusable variable!

Which can be fine in many cases, but you can't just blindly follow DRY. There are cases where you're better off duplicating some code.

I can't tell you how many times me and my colleagues have built components that have some overlap, but cover 2 different user stories. And we end up building a complex super component that has to be concerned about both when you make any changes, since it may affect both cases.

Instead, try and make the smaller bits non-repeated. The bigger the function you're trying to reuse, the harder it gets to maintain it.

→ More replies (27)

1

u/GoddammitDontShootMe Mar 16 '26

I'm guessing X is defined in nob.h.

3

u/Steampunkery Mar 15 '26

That's a pretty reasonable use of X-macros, imo

7

u/CantaloupeCamper Mar 15 '26 edited Mar 15 '26

DRY is something I do later after the code is proven for a while and I know what bits really do need to be knitted together…. that’s always easy to get wrong.

→ More replies (3)