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

119

u/[deleted] Jun 09 '20

I don’t fully agree this is bad code. This depends a lot on the context like:

  • is there a company rule that requires every assignment to be documented (in which case the rule itself is the “problem”, not the code)

  • the name magic number might be very meaningful to everyone working on this project or even the whole industry (I’m not a game dev so I don’t know but I’ve seen the term magic number in other software where people were aware of its meaning)

-26

u/scandii Jun 09 '20

the fact that this thread exists speaks for the fact that it is bad naming.

naming standard number one:

always without fail name your variables after what they are. the number is something, be it an ID, result of an operation, captured data etc.

5

u/GasolinePizza Jun 09 '20

The actual term for this value is "magic number". This is the correct name for this variable. Clear, concise naming does not include defining terms in the definition name for readers ignorant to the problem domain.

Edit: Just to clarify, I mean ignorant in the neutral sense, not the hostile form as an insult.