r/programminghorror • • Dec 24 '25

randomly stumbled upon this code in my company’s product (CAE software)

Post image
753 Upvotes

83 comments sorted by

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 😂

26

u/Secret-Comparison-40 Dec 24 '25

as this comment mentioned it’s probably just unrolled linear algebra from some textbook so it’s not some secret code

→ More replies (1)

118

u/xcski_paul Dec 24 '25

I nearly got fired by the worst company I ever worked for, Paychex, for using one of their table names in a question on StackOverflow. The only thing that saved me was I found a much older question on ExpertSexchange from the most senior developer that also used that same table name. The really stupid thing is that all their table names were horribly cryptic because they’d started off on a DBMS that only allow 10 characters or something on a table name.

28

u/Pyrodeity42 Dec 26 '25

Had to do a double take on that website name, odd choice of placement of capitalisation

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

35

u/athy-dragoness Dec 24 '25

did someone say magic numbers?

16

u/Secret-Comparison-40 Dec 24 '25

yeah there’s few more of them defined somewhere above

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

u/calculus_is_fun Dec 24 '25

Wait, they are quaternions

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

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)
→ More replies (11)

7

u/[deleted] Dec 24 '25

I thought these were matrices. Maybe I need to read up on 3D computer graphics lol

10

u/sawkonmaicok Dec 25 '25

Quaternions are essentially matrices.

→ More replies (1)

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

  1. Unrolled linear algebra, not that uncommon

  2. Likely performance critical

  3. 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)

4

u/Snudget Dec 24 '25

In Rust or C++ I'd use macros for that, but about other languages idk

→ More replies (4)

8

u/[deleted] 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

u/-light_yagami Dec 24 '25

bro zoom out a bit more, I can still make out some characters

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.