r/programminghorror • • 19d ago

c++ Old code I made years ago

Post image
123 Upvotes

15 comments sorted by

12

u/TingleWizard 15d ago

Nice game of spot the difference.

9

u/Pupaak 15d ago

I mean its not THAT bad

6

u/SeaMango1064 14d 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 13d 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 19d ago

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

35

u/_Ilobilo_ 19d ago

what?

10

u/YysrID4gYW55IG90aGVy 19d 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_ 19d ago

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

6

u/YysrID4gYW55IG90aGVy 19d ago

Then I take it back

1

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

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

2

u/throw3142 14d ago

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

4

u/YysrID4gYW55IG90aGVy 14d ago

3

u/throw3142 14d ago

Madness!

3

u/Probable_Foreigner 7d 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 14d ago

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