Globals or objects?

tinnews at isbd.co.uk tinnews at isbd.co.uk
Sat Feb 23 04:32:24 EST 2008


Steven D'Aprano <steve at remove-this-cybersource.com.au> wrote:
> 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.
> 
That's *exactly* what I was saying in the bit you snipped!  :-)

However it doesn't answer the OP's questionas to why he was advised to
replace a global with a class *without* changing the way it was used.

-- 
Chris Green



More information about the Python-list mailing list