ethical questions about global variables

Giampaolo Rodola' gnewsg at gmail.com
Tue Dec 16 07:19:57 EST 2008


On 16 Dic, 07:23, Michele Simionato <michele.simion... at gmail.com>
wrote:
> On Dec 16, 3:45 am, "Giampaolo Rodola'" <gne... at gmail.com> wrote:
>
> > Hi,
> > in a module of mine (ftpserver.py) I'd want to add a (boolean) global
> > variable named "use_gmt_times" to decide whether the server has to
> > return times in GMT or localtime but I'm not sure if it is a good idea
> > because of the "ethical" doubts I'm gonna write below.
>
> Global variables have a bad reputation, but they are not
> so bad in Python. Notice that:
>
> 1. global variables in Python are local to the module they
>    are defined in;
>
> 2. class names and module names are usually global variables
>    and nobody complains about that.
>
> 3. if you use an ALL_CAPS convention it is quite quite clear
>    that you are using a global variable.
>
> Actually the ALL_CAPS convention is for constants, but
> sometimes I use it for configuration variables too, if
> they are set at the beginning and they are never changed
> during the running of the program. If you have more than
> a single global, it makes sense to introduce a configuration
> object, as others have said (this is how typically work)
> but if you have a single parameter the confuguration
> object is not worth the effort, IMO.
>
>                  M. Simionato

No, all the other "configurable" variables are offered as class
attributes.


--- Giampaolo
http://code.google.com/p/pyftpdlib/



More information about the Python-list mailing list