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?

40

u/evanratt Jun 09 '20

Magic Number is an actual term when using UDP connections: https://tools.ietf.org/html/draft-herbert-udp-magic-numbers-00

Someone who is familiar with UDP would look at this code and know what a "magic number" is, because it's the correct term. UDPConnectionID could actually introduce confusion by creating a new term, rather than using the accepted canonical term for this value.

7

u/tuckmuck203 Jun 09 '20

Wild how domain knowledge can immediately change something from "what the fuck" to "why the fuck would you do otherwise". I wish more "bad code" was like this.