MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/badcode/comments/gzhnbb/ea_published_their_commandconquer_code_on_github/ftgnj82/?context=3
r/badcode • u/Achereto • Jun 09 '20
36 comments sorted by
View all comments
36
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.
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. 5 u/KernowRoger Jun 09 '20 But why call it magic number and not like connectionId? 9 u/locuester Jun 09 '20 edited Jun 09 '20 ConnectionId would imply usefulness to someone debugging. Magic number makes it clear that it’s used as a [magic number](https://en.m.wikipedia.org/wiki/Magic_number_(programming)) 2 u/TheSpiffySpaceman Jun 09 '20 I think the last parenthesis of your URL escaped the URL formatting... 3 u/locuester Jun 09 '20 Thx. Fixed.
38
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.
5 u/KernowRoger Jun 09 '20 But why call it magic number and not like connectionId? 9 u/locuester Jun 09 '20 edited Jun 09 '20 ConnectionId would imply usefulness to someone debugging. Magic number makes it clear that it’s used as a [magic number](https://en.m.wikipedia.org/wiki/Magic_number_(programming)) 2 u/TheSpiffySpaceman Jun 09 '20 I think the last parenthesis of your URL escaped the URL formatting... 3 u/locuester Jun 09 '20 Thx. Fixed.
5
But why call it magic number and not like connectionId?
9 u/locuester Jun 09 '20 edited Jun 09 '20 ConnectionId would imply usefulness to someone debugging. Magic number makes it clear that it’s used as a [magic number](https://en.m.wikipedia.org/wiki/Magic_number_(programming)) 2 u/TheSpiffySpaceman Jun 09 '20 I think the last parenthesis of your URL escaped the URL formatting... 3 u/locuester Jun 09 '20 Thx. Fixed.
9
ConnectionId would imply usefulness to someone debugging. Magic number makes it clear that it’s used as a [magic number](https://en.m.wikipedia.org/wiki/Magic_number_(programming))
2 u/TheSpiffySpaceman Jun 09 '20 I think the last parenthesis of your URL escaped the URL formatting... 3 u/locuester Jun 09 '20 Thx. Fixed.
2
I think the last parenthesis of your URL escaped the URL formatting...
3 u/locuester Jun 09 '20 Thx. Fixed.
3
Thx. Fixed.
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.