Globals or objects?

Aahz aahz at pythoncraft.com
Thu Feb 21 08:25:58 EST 2008


In article <72b59db8-ec9c-480a-9ae7-92a69acb70a6 at 41g2000hsc.googlegroups.com>,
 <MartinRinehart at gmail.com> wrote:
>
>I had a global variable holding a count. One source Google found
>suggested that I wouldn't need the global if I used an object. So I
>created a Singleton class that now holds the former global as an
>instance attribute. Bye, bye, global.
>
>But later I thought about it. I cannot see a single advantage to the
>object approach. Am I missing something? Or was the original global a
>better, cleaner solution to the "I need a value I can read/write from
>several places" problem?

The advantage of the global singleton is that it is a container; 
therefore, its contents are mutable and you don't need to keep using the 
``global`` statement.
-- 
Aahz (aahz at pythoncraft.com)           <*>         http://www.pythoncraft.com/

"All problems in computer science can be solved by another level of     
indirection."  --Butler Lampson



More information about the Python-list mailing list