Solved Why capital letters for constants? FRFreyaLOP 9 Sep, 16:29 Python doesn't enforce constants. Why bother with GRAVITY instead of gravity?
SOSophieDev9 Sep, 21:56 Solutionreplies: 2It's a convention (PEP 8): UPPER_CASE tells every reader "this value is fixed, don't change it". Python won't stop you, but other developers (and linters) will.
JAJackStack10 Sep, 11:24Just realised the whole "magic number" thing is about the next person reading the code, which is often future me.
NONoahLoops10 Sep, 08:53Exactly. And when Mars gravity comes along in stage 3, you see why named values are worth it — change one line, not ten.
Comments 4
Join the discussion CommentAlready have an account? Log in
It's a convention (PEP 8): UPPER_CASE tells every reader "this value is fixed, don't change it". Python won't stop you, but other developers (and linters) will.
So it's communication, not protection.
Just realised the whole "magic number" thing is about the next person reading the code, which is often future me.
Exactly. And when Mars gravity comes along in stage 3, you see why named values are worth it — change one line, not ten.