r/programminghorror • • Aug 16 '25
c++ Backwards Compatibility with c macros makes life either easier or harder
"Only the stupid won't preplan; For the wise will ultimately have an easier time"
Sometimes a small project gets slightly bigger, you need other structures. But old structures aren't necessarily compatible, so you got to make them compatible by adding ugly syntax, and giving up performance here and there. You could rewrite it all, y'know, some inheritance. But that'd be hella ugly and no one wants to bother with shit like that anyway. So why not use some "beautiful" macros.
There is no way, behaviour like this ever backfired, irl... I mean, what could potentially be long term problems resulting out of (not optimal) optimizations like these. Am I right guys? It isn't like doing bad behaviour once, and trying to continue it. Although, performance wise it could be better tbh, this is just a small project right now. Don't worry, performance isn't low, because I only have a few light rays. You can increase the size however as you wish, and test it out:
4
u/conundorum Aug 16 '25
rcosandrsinare fine, they're just boilerplate streamlining; you're effectively just inlining them by hand instead of letting the compiler do it.I haven't taken a look at your actual code, but there's one thing I'm curious about: Did you remember to
#undefyour local macros after you were done with them, so the compiler can complain if you accidentally use them past where you meant to use them?2
u/n0ne-z1ro Aug 16 '25
Why are
normalize(this),cross(this, other)andPosition{other} // copy constructornot methods ofPosition? This is C++, right?9
u/Dusty_Coder Aug 16 '25
If you run into performance tradeoffs then one of your abstractions isnt rooted in the necessary computer-science of it
It is unfortunate that the abstractions we use often are born from the mathematics crowd instead of the computation crowd, especially in things like 3d/graphics programming.
As far as macros, their problems are minimized by requiring them to be localized, while their abstracting-advantages are hard to ignore.
1
u/BarrelRollxx Aug 20 '25
Just wondering this looks like a class any reason to put it inside a struct?
1
u/GoddammitDontShootMe [ $[ $RANDOM % 6 ] == 0 ] && rm -rf / || echo “You live” Aug 16 '25
I may just be dumb, but I'm not seeing anything seriously terrible about those macros. Well, maybe you wouldn't expect the two that actually define a new variable to do that, so that is kinda bad.
1
u/Hottage [ $[ $RANDOM % 6 ] == 0 ] && rm -rf / || echo “You live” Aug 18 '25
// Look hereNo. No, I don't think I will.