initializing mutable class attributes
Mel Wilson
mwilson at the-wire.com
Wed Sep 1 11:35:08 EDT 2004
In article <8JbZc.140699$UTP.23045 at twister01.bloor.is.net.cable.rogers.com>,
"Dan Perl" <dperl at rogers.com> wrote:
>When learning something, I need to understand the 'WHY' behind a design
>decision like that, when clearly there are alternatives. I will not be
>satisfied with an explanation of "that's the Python way and you just have to
>learn it". The explanation of choosing "explicit" instead of "implicit"
>makes sense and helps me in better understanding Python. I have to mention
>though that I do not accept "explicit is better than implicit" as an
>absolute truth.
That's the "Zen" part. Cf. Neils Bohr's definition of a
Great Truth: a Great Truth is a proposition whose opposite
is also a Great Truth.
> . [That's like when someone told me once with pride: "I
>always design bottom-up."]
:)
A: I always design bottom-up. This is my latest application.
B: What is it?
A: I don't know.
We know where we stood the ladder, but aside from "up",
we can't say much about where it goes.
> [ ... ]
>You may see in another message I posted in this thread that I ended up
>giving an answer to my own question (the 'WHY' question). Here is my reason
>for that 'WHY'. Python does not have method overloading (and I am ok with
>that, because it comes with the dynamic typing), so you cannot have a
>default constructor and a non-default one at the same time. C++ and Java
>have overloading and then can also mandate a default constructor for a
>parent class, even if it's empty because you actually use only a non-default
>constructor for that class. Python cannot request that you also implement a
>default __init__ when you need a non-default one. There would be the
>possibility of adding another special method, but there's already __init__
>and __new__, so that would be too confusing.
I think the difference between:
class B (A):
def __init__ (self, ...)
... B related stuff
A.__init__ (self, ...)
class B (A):
def __init__ (self, ...)
A.__init__ (self, ...)
... B related stuff
class B (A):
def __init__ (self, ...)
... B related stuff
A.__init__ (self, ...)
... more B related stuff
shows that it's simplest just to code what you want done..
and that's without looking at multiple inheritance,
or different argument lists between A's and B's __init__.
Regards, Mel.
More information about the Python-list
mailing list