Re: Costly object creation (was : Having Trouble with Scoping Rules)
Available news archives: comp.lang.tcl - comp.lang.python - comp.security.firewalls - sci.crypt - comp.lang.php - comp.lang.javascript
Google
 
Web news.hping.org


comp.lang.python archive

Re: Costly object creation (was : Having Trouble with Scoping Rules)

From: Charles Krug <cdkrug@aol.com>
Date: Tue Jan 31 2006 - 14:15:42 CET

On 2006-01-31, bruno at modulix <onurb@xiludom.gro> wrote:
> See other answers in this thread for how to solve the UnboundLocalError
> problem.
>
> Now about your *real* problem - which is nothing new -, you may want to
> read about some known solutions:
>
> http://en.wikipedia.org/wiki/Singleton_pattern
> http://en.wikipedia.org/wiki/Proxy_pattern
> http://en.wikipedia.org/wiki/Lazy_initialization
> http://en.wikipedia.org/wiki/Memoization
>

No, I'm already quite certain that this is a Singleton--pythonically a
module-level instance of Something--I'm not thinking of it as "lazy
instantiated" 'cuz it's initialized at startup, but I suppose it
qualifies.

I considered using a Borg for this, but discarded the idea as "too
complicated for my needs--this will be easier to implement . . . "

Which I suppose it would be if I knew how correctly to use the "global"
keyword.

I don't need to restrict the actual class to One Instance so much as I'd
prefer that to be the default behavior. I can't think of a reason why
I'd want to subclass this, so I can't say whether it makes sense to
Borg/Highlander/Singleton it or not. For now, I'll Do The Simplest
Thing That Might Work and figure YAGNI (or IAGNI, I guess).

Thanks for the help.
Received on Tue Feb 7 20:20:19 2006