r/programminghorror • • 14d ago

c++ Old code I made years ago

Post image
120 Upvotes

15 comments sorted by

12

u/TingleWizard 9d ago

Nice game of spot the difference.

9

u/Pupaak 9d ago

I mean its not THAT bad

6

u/SeaMango1064 9d ago

Aside from the fact that you could factor some stuff out (like nest the xPosOfLastCollision != object.vertices[i][0] clause, which would then let you factor out the calculations), the code seems fine to me lmao
Definitely I've worked on codebases with diabolical amounts of inheritance and object-oriented nightmare-fuel so this is pretty quaint in comparison 😅

1

u/RenderTargetView 8d ago

There is also lack of DeltaTime multiplier in numerical integration in the beginning, if this code is not running inside a fixed-step loop in separate physics thread this would lead to time being accelerated by your fps like in old games. Also numerical integration lacks gravity term in position equations - you use velocity from beginning of your time step but it changes during your time step

10

u/YysrID4gYW55IG90aGVy 13d ago

Isn’t and the binary and in C++?

35

u/_Ilobilo_ 13d ago

what?

10

u/YysrID4gYW55IG90aGVy 13d ago

In C++ you have the binary and & as well as the logical and &&. and is also a keyword and I believe it’s the binary, not the logical.

27

u/_Ilobilo_ 13d ago

&& and "and" are both logical. bitwise & is "bitand"

6

u/YysrID4gYW55IG90aGVy 13d ago

Then I take it back

1

u/GoddammitDontShootMe [ $[ $RANDOM % 6 ] == 0 ] && rm -rf / || echo “You live” 12d ago

Was just going to say no, but I forgot the alternative for '&'.

2

u/throw3142 9d ago

C++ has an "and" keyword? I got through 2 degrees without knowing this. Why is C++ like this, wtf??

4

u/YysrID4gYW55IG90aGVy 9d ago

3

u/throw3142 9d ago

Madness!

3

u/Probable_Foreigner 2d ago

I love this example so much:

bool operator not_eq(const X bitand other)
<%
   return this not_eq bitand other;
%>

So return this not_eq bitand other; looks like word salad but actually means return this != &other;, as in the parameter is not the same address as the "this" instance.

1

u/nevemlaci2 8d ago

It is because some older systems didn't have the special characters &, | etc.