Borg - is that a singleton?

Giovanni Bajo noway at sorry.com
Mon Mar 3 07:13:44 EST 2003


"Alex Martelli" <aleax at aleax.it> ha scritto nel messaggio
news:f3_7a.342065$AA2.12778796 at news2.tin.it...

> I find your suggested approach a bit fragile, because it conflates
> issues of class initialization with ones of instance initialization.
> Consider, with your implementation of Borg:
>
> class Super(Borg): pass
> class Sub(Super): pass
>

I had some feeling my code was weak wrt inheritance, thanks for clarifying
this.
You say that my code is conflating "class initialization" and "instance
initialization". Would you please elaborate on this issue? Can you show me
in my code what is part of "class inizialization" and what of "instance
initialization", and why is it bad to keep them together?

As a Python beginner (with C++ background), I was not able to find
satisfactory documents explaining how to code OO in a stricly pythonic way,
which is a bit frustrating, because I am just looking at others' code
snippets to learn. This helps of course, but I would be more comfortable if
I could read some essay on it. Any suggestion?

> in class scope, you're probably better off generating the magic
> _shared_state in a custom metaclass, e.g.:

I still need to look at metaclasses, so your code is black magic for me,
right now :) I will review your code later, thanks anyway.

Thanks
Giovanni Bajo






More information about the Python-list mailing list