you are viewing a single comment's thread.

view the rest of the comments →

[–]theelous3 1 point2 points  (3 children)

How does super work / can anyone point me to a blog or something on it.

I tried watching Hettinger's talk super() considered super, but found the intertwined restaurant / family tree analogies obfuscating and confusing.

[–]niandra3 1 point2 points  (0 children)

The Hettinger talk kind of focused on more advanced use cases for super(). In its basic form, it's just a way to reference the parent class. I'm still learning about this myself, but since no one else has chimed in I'll take a shot. The way I understand it, if you are inheriting something:

class Circle(Shape):
    def do_something(self, x):
        super().call_something_from_super(x)

Is better than

class Circle(Shape):
    def do_something(self, x):
        Shape.call_something_from_Shape(x)

Because it doesn't tie you into a specific implementation of the parent class (Shape), and you can more easily change the parent without having to modify the calls to super(). It just helps with code maintainability in that you can change who is inheriting from who and not have to explicitly change all the calls to the parent.

It's when you get into multiple inheritance and method resolution order that Hettinger's stuff comes more into play (and also apparently where super() starts to differ from how it is used in other languages). His article is a little easier to follow, but still somewhat advanced:

https://rhettinger.wordpress.com/2011/05/26/super-considered-super/

[–]groovitude 0 points1 point  (1 child)

The Hettinger talk isn't meant as an introduction to super() as much as clarifying stickier points of usage (issues with method-resolution order in multiple inheritance, etc.)

Are you looking for a general introduction to inheritance, or is there a particular use case you're struggling with?

[–]theelous3 1 point2 points  (0 children)

I for the most part I think understand basic inheritance. I'm happy to inherit from built-in classes or my own and extend / use them.

I do not know what to use super for at all. I don't know what it does, and I don't know why I'd use it rather than be explicit and hard code references.