OOP / language design question
I was wondering, why you always have to remember to call bases' constructors explicitly from the derived class constructor? Why hasn't this been enforced by the language? -- http://mail.python.org/mailman/listinfo/python-list
Re: OOP / language design question
Diez B. Roggisch wrote: > I have another question for you: why does JAVA enforce that a constructor of > a base-class must be called prior to everything else in the derived class's > constructor? Well, I can imagine it's done to make sure that the base(s) are properly constructed. Sound s sensible to me. > No way to do some computing for parameters that I want to pass > to the parent constructor... Try this: Derived::Dreived() : Base(calcParam1(), calcParam2()) ... > Besides, this automatically base-constructor-calling only happens for the > most trivial of cases - the no-argument-constructors. Well, the language can at least ensure that theconstructor is called - i.e. either call it automatically if it can be called without parameters, or fail with error. -- http://mail.python.org/mailman/listinfo/python-list
Re: OOP / language design question
Heiko Wundram wrote: > Because sometimes you don't want to call the base classes constructors? Sounds strange to me at the moment, but I'll try to adjust to this thought. > Python zen says: "Better explicit than implicit," and in this case it hits > the nail on the head. Better to see right away what your code does (the > explicit call to the base class), than to have to work around calling a bases > constructor if you don't want to call it. Thanks, that explains it somehow - at least, it's consistent with explicit "self". I think I'll need some shift in thinking after C++. -- http://mail.python.org/mailman/listinfo/python-list