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.
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?
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.
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.
36
u/Achereto Jun 09 '20
You can find that piece of code here: https://github.com/electronicarts/CnC_Remastered_Collection/blob/master/REDALERT/CONNECT.CPP#L98
Why is it bad?
The comment adds nothing to your code that isn't already explained by the code.
The name "magic number" is a very bad choice since it's not explanatory.
lots of visual noise around the code.