DEV Community

Discussion on: local constants vs comments

Collapse
 
alainvanhout profile image
Alain Van Hout • Edited

I'd go with the second approach, but when needed I'd add a comment explaining concretely why that value is the only correct value.

Collapse
 
peledzohar profile image
Zohar Peled

Well, this is just a silly example, real code would have things like if(event.code == 1903) // own goal vs
const int ownGoal = 1903;...if(event.code == ownGoal) - so no, you don't really need the comment. I also tend to pick the second option, but I can't really explain why - it just feels like a better option...