r/badcode • • Jun 09 '20

c++ EA published their Command&Conquer Code on github. This is my favorite part so far.

Post image
1.6k Upvotes

36 comments sorted by

View all comments

Show parent comments

38

u/gu3st12 Jun 09 '20

It's not the worst tbh. It looks bad out of context, but given how UDP works, you need some value that represents a specific "connection" to the server.

11

u/Achereto Jun 09 '20

So what does "magic number" do? Does it cast some magic? Or does it identify a UDP Connection? If the latter, why isn't it named "UDPConnectionID" or something similar? Wouldn't that be much more readable?

10

u/web8564j Jun 09 '20

I think this is a valid question, not sure why it's been downvoted. I can only think that magicnumber would be ok if it's litterally called magic number in whatever protocol is being processed.

Otherwise I completely agree, UDPConnectionID would be loads better.

2

u/[deleted] Sep 30 '20

I know this is an old comment, but that's actually exactly the case here. Apparently, UDP does use the term magic number as part of the protocol. At least that's what I found out from other comments here.