Why is the implicit character super () a desirable feature?

This is a kind of additional question regarding a very popular questionsuper( ) . The question was basically “Why should I use, super( )” and the answer was “Because you don't need to reference the parent class, which may be nice.”

My question is: why is it good in the world? What happened to "Explicit is better than implied?" Let's say I read some other developer code, and I see:

class Foo(Bar, Baz):
    def my_method(self):
        super(Foo, self).who_knows( ) #nobody knows!

Now I need to dig through the documents on Barand Bazand all their parent classes to the tree to find out where it comes from and where who_knows( ). I also need a perfect understanding of the resolution order of the method in order to find out which one is who_knows( )actually being called.

Now look at the same code without super( ):

class Foo(Bar, Baz):
    def my_method(self):
        Baz.who_knows(self) #ah, Baz knows

Much clearer, no need to guess or understand the MRO.

I do not raise this issue to start a debate or philosophical discussion. I just hope that someone can show me some very clear examples in which an implicit character is super( )really desirable, because, to be honest, I do not see it.

+4
source share
2 answers

When you delegate implementations to other parts of the code, “explicitly” about how this code is written is detrimental to the goal. Knowing exactly what is called equates to being dependent on this implementation, so if one part of the code changes, the other also needs to change.

, Baz.who_knows(self). Baz who_knows, , Baz . , Foo, , ? Baz, Foo ( ).

+1

, , super(Foo, self).who_knows() . self.who_knows().

super() .

+2

All Articles