Accessing parent objects

Steven D'Aprano steve+comp.lang.python at pearwood.info
Sun Mar 25 18:41:07 EDT 2018


On Sun, 25 Mar 2018 13:30:14 -0700, Rick Johnson wrote:

[...]
>> Especially since by your own admission, you are *giving up correctness*
>> in order to buy "consistency":
> 
> "sacrificing correctness" only in a purely ideological sense.
> 
> Explicit inheritance (aka: hard-coding the superclass symbol) works just
> as well as implicit inheritance (aka: relying on the "resolution magic"
> of super). 

Except when it doesn't, which is precisely why super was introduced in 
the first place.

(A minor point: if you're going to quote me, quote me correctly: I said 
*giving up* not "sacrificing".)

If your new-style classes don't use super, then they *literally* are 
incorrect, and are either buggy, or have a figurative landmine in your 
class, waiting to go off and introduce a bug if someone is unlucky enough 
to inherit from it under the right circumstances.

Hint: google on "inheritance diamond problem", and maybe you will learn 
something.

You might be lucky enough to use that class for a decade, and never be 
bitten by the flaw. If you never match those right circumstances (or 
perhaps that should be the wrong circumstances), then the flaw will never 
express itself and you may escape introducing an inheritance bug. But 
nevertheless, it will still be there, in your classes, ready to blow up 
in your face.


> Of course, in the former case, a slight bit of onerous is
> placed on the programmer because he/she must know the exact spelling of
> the superclass symbol, whereas, OO's `super` is nothing but a lazy
> shortcut which looks up and returns the symbol for you.

No, *Ruby's super* is nothing but a lazy shortcut. Python's super does a 
lot more.


-- 
Steve




More information about the Python-list mailing list