Globals or objects?

Steven D'Aprano steve at REMOVE-THIS-cybersource.com.au
Fri Feb 22 19:23:03 EST 2008


On Fri, 22 Feb 2008 18:53:54 +0000, tinnews wrote:

>> > But you're not comparing what the OP posted.  He was comparing a
>> > global with an object with a single variable inside it.  Either would
>> > work with the y = spam(arg) example above.
>> 
>> What do you mean by "an object with a single variable inside it"? I
>> don't understand what that is supposed to mean, or why you think it is
>> the same as a global. Do you mean a Singleton?
>> 
>> If so, then the answer is simple: using a Singleton argument instead of
>> a global is better, because with a global you are stuck to always using
>> the global (at least until you can re-write the code), but with the
>> Singleton argument, you may be enlightened and *not* use a Singleton.
>> 
> But if you stop using the Singleton the code no longer does the same as
> it would with a global does it?

That's a *good* thing, not a problem. The whole idea is to get away from 
the bad behaviour of globals, not find some other way to implement it.



-- 
Steven






More information about the Python-list mailing list