Thredu
codecompassProgramming

Magic numbers vs named constants: where do you draw the line?

A reviewer asked me to replace a 60 with SECONDS_PER_MINUTE. I get the principle, but at some point it feels like naming things for the sake of it.

My rough rule: if the number has meaning in the domain or appears more than once, name it. If it's obviously a 0, 1 or a loop bound, leave it. Where do you land?

Comments · 0

No replies yet — start the conversation.