r/programminghorror • u/vadnyclovek [ $[ $RANDOM % 6 ] == 0 ] && rm -rf / || echo "You live" • Mar 15 '26
When you take DRY too seriously.
231
Upvotes
r/programminghorror • u/vadnyclovek [ $[ $RANDOM % 6 ] == 0 ] && rm -rf / || echo "You live" • Mar 15 '26
54
u/joe-knows-nothing Mar 15 '26
First time seeing platform specific #defines, eh?
103
u/tvardero Mar 15 '26
Compiler will inline it anyway
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 )
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?
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
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.
1
u/GoddammitDontShootMe [ $[ $RANDOM % 6 ] == 0 ] && rm -rf / || echo "You live" 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
3
u/nekokattt Mar 16 '26
nob.h
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.
2
u/no_brains101 Mar 16 '26 edited Mar 16 '26
It was not seeming like, completely awful. A bit cursed but maybe like it was for a good reason.
At least until I saw FLOAT_VALUES(COMMA)
Am I ignorant of something or is that crazy
At first seeing FLOAT_VALUES I was like, ok, so, platform specific floats, whatever. COMMA though, now I'm confused. You lost me. I'd need to actually read the thing.
2
u/robhanz Mar 16 '26
DRY is the most overused and misapplied principle ever.
Originally it was really more about business logic - if submitting a form 235A means that a Foobozzle record should get made? That should exist in one place in the code.
However, programmers love to "solve" the general case, even when that "solution" creates a hybrid monstrosity that tries to encapsulate 20 different use cases with 10% overlap. They'd rather maintain that massive complexity than just write... really simple code 20 times.
2
u/GoddammitDontShootMe [ $[ $RANDOM % 6 ] == 0 ] && rm -rf / || echo "You live" Mar 16 '26
So basically you have to chase down these macro definitions all because the author didn't want to repeat a few lines of code more than once?
1
u/Sexy_Koala_Juice Mar 16 '26
All the typedefs strewn randomly throughout the code is disgusting
1
u/MMORPGnews Mar 16 '26
As long as it's works, it's fine.
1
u/ILoveTiramisuu Mar 17 '26
difference between delete_dir and delete_entire_dir?
1
u/Competitive-Ebb3899 Mar 18 '26
There must be a better way to share code besides creating a huge screenshot.
1
u/the_inoffensive_man Mar 20 '26
I don't C the problem.
1
u/Unknown_TheRedFoxo Mar 16 '26
those x-macros oh gosh
0
u/boiledbarnacle Mar 15 '26
Just make sure recursive macros start first with the termination condition.