style Q: global vars in CAPS?

Peter Hansen peter at engcorp.com
Tue Apr 2 20:15:40 EST 2002


Andrei Kulakov wrote:
> 
> Hello,
> 
> What do you think about global variables spelled in caps? Is that what
> most people do?

More commonly ALL CAPS is a convention that signifies "constant",
not "global".  If the globals in question are constants and not
variables, I'd say "yes".

If they're really variables, a different convention I've seen
more often is to prefix "g_" or just "g", as in gSomeGlobal.

And of course you should minimize the use of globals as much
as possible, since they can lead to all kinds of difficulties
if you are not careful.  (Although they are sometimes necessary,
as discussion in the XP mailing list has recently covered.)

-Peter



More information about the Python-list mailing list