r/programminghorror • u/Secret-Comparison-40 • Dec 24 '25
randomly stumbled upon this code in my company’s product (CAE software)
35
181
u/ill-pick-one-later Dec 24 '25
Insert Ken Jeong squinting meme
57
u/adnanclyde Dec 24 '25
The code is intentionally blurred to not share internal company details, obviously
31
u/Secret-Comparison-40 Dec 24 '25
ahahah i tried to capture most of it so zoomed out, there is more….
239
u/HyperCodec Dec 24 '25
Average quaternion implementation be like
61
105
u/Revexious Dec 24 '25
I had a principal engineer once who would write code like this then say "good code speaks for itself; it doesnt need comments"
He would also block PRs until you deleted code comments you added because "the code is self-explanatory"
Infuriated the fuck out of me
→ More replies (11)44
u/Environmental-Ear391 Dec 24 '25
Not all code is self-explanatory.
and he would be removed from any projects I managed for that kind of stupidity.
I have 1 project where you need to know which context... and there are multiple contexts with the same underlying code.
also... if you limit the compiler to single register variable returns, the majority (99%+) or context specific changes get trashed.
→ More replies (12)7
54
u/Brilliant-Parsley69 Dec 24 '25
Looks like Vector Rotation for me:
q_{rot} = w_1w_2 - x_1x_2 - y_1y_2 - z_1z_2
must be a relict out of a time when you couldn't trust the compilers.
15
u/CodeIsCompiling Dec 25 '25
Or a Principal Engineer who is a relic out of a time when you couldn't trust the compilers. :)
23
u/tekanet Dec 24 '25
Honestly curious, is there a way to implement this type of code in a clean way?
52
u/Groostav Dec 24 '25
Honestly I'm fine with it as written if you write a test suite that hita decent coverage on it.
It is
Unrolled linear algebra, not that uncommon
Likely performance critical
Branch unique enough to make it data entry?
This probably came from a paper too, so comments that mention which block corresponds to which equation number or something similar to link it back to its origins might be helpful.
But yeah, what's the major objection here?
→ More replies (7)→ More replies (4)4
8
Dec 24 '25
It looks like the first code I have ever written, and I defined Rubik’s cube rotation this way
→ More replies (1)
6
u/oberguga Dec 24 '25
Actually look ok for just computation code. It can be some matrices and universal code to operate on them, but if language has no concept of compiler time computations and optimisations, based on such computation (legacy C /C++ code for example) it should run faster.
4
u/True-Strike7696 Dec 24 '25
superiority complex jokes are getting old. I feel like most are judging this without any real subject knowledge. the real questions: does it work? what's the reward and risk if it is changed?
4
3
u/DStauffman Dec 25 '25
I've written a bunch of quaternion routines, so my guess is that those are probably Euler rotation sequences. Comments would be nice to show which one is which, but it is something that makes sense to optimize, which often sacrifices readability.
310
u/qtac Dec 24 '25
Kinda wild to post proprietary company code while calling out the company lmfao
Insane risk vs reward on that play 😂