[Tutor] global is bad but ...

Eric Brunson brunson at brunson.com
Tue Nov 13 18:25:22 CET 2007


Kent Johnson wrote:
> ---- Dinesh B Vadhia <dineshbvadhia at hotmail.com> wrote: 
>   
>> Consider a data structure (say, an array) that is operated on by a bunch of functions
>>
>> The described way is to place the statement 'global' in line 1 of each function.  On the other hand, wiser heads say that the use of 'global' is bad and that reworking the code into classes and objects is better.
>>
>> What do you think and suggest?
>>     
>
> Yes, global is bad.
>
> - Pass array_G as a parameter to each function
> or
> - Make all three functions methods of a class with array_G as an attribute.
>   

Global is almost always bad.  Sometimes you can make a valid argument 
that information truly has a global context, such as a debug flag, or 
the parsed options that were passed from the command line.

Different philosophies...

> Kent
>   
>> Dinesh
>>     
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>   



More information about the Tutor mailing list