Question about scope
Pat
Pat at junk.net
Sat Nov 1 08:34:21 EDT 2008
Steven D'Aprano wrote:
> On Thu, 23 Oct 2008 11:38:35 -0400, Pat wrote:
>
>> I have a Globals class.
>
> Well, that's your first mistake. Using global variables in a class is no
> better than using bare global variables. They're still global, and that's
> a problem:
>
> http://weblogs.asp.net/wallen/archive/2003/05/08/6750.aspx
>
>
It depends upon the situation.
In my program, I have one routine that loads a bunch of files and
initializes a number of variables. After that, the values in the
globals class never change. It's a lot easier to maintain this type of
code than to passing the same variables from function to function to
function.
On the other hand, if multiple functions were willy-nilly changing
global variables then globals would be a maintenance nightmare.
To unilaterally state that globals are always "evil" borders on a
subjective religious conviction.
More information about the Python-list
mailing list