[Python-Dev] Re: super() harmful? (original) (raw)
Guido van Rossum gvanrossum at gmail.com
Wed Jan 5 19:23:01 CET 2005
- Previous message: [Python-Dev] Re: super() harmful?
- Next message: [Python-Dev] Re: super() harmful?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
The issue of mixing super() and explicit calls to the superclass's method occur with any method. (Thus making it difficult/impossible for a framework to convert to using super without breaking client code that subclasses).
Well, client classes which are leaves of the class tree can still safely use BaseClass.thisMethod(self, args) -- it's only classes that are written to be extended that must all be converted to using super(). So I'm not sure how you think your clients are breaking.
Adding optional arguments to one branch of the inheritance tree, but not another, or adding different optional args in both branches. (breaks unless you always pass optional args as keywordargs, and all methods take **kwargs and pass that on to super).
But that breaks anyway; I don't see how using the old Base.method(self, args) approach makes this easier, unless you are using single inheritance. If you're expecting single inheritance anyway, why bother with super()?
> Super is intended for use that are designed with method cooperation in > mind, so I agree with the best practices in James's Conclusion: > [[omitted]] > But that's not the same as calling it harmful. :-(
The 'harmfulness' comes from people being confused by, and misusing super, because it is so very very easy to do so, and so very hard to use correctly.
And using multiple inheritance the old was was not confusing? Surely you are joking.
From what I can tell, it is mostly used incorrectly. Especially uses in init or new. Many people seem to use super in their init methods thinking that it'll magically improve something (like perhaps making multiple inheritance trees that include their class work better), only to just cause a different set of problems for multiple inheritance trees, instead, because they don't realize they need to follow those recommendations.
If they're happy with single inheritance, let them use super() incorrectly. It works, and that's what count. Their code didn't work right with multiple inheritance before, it still doesn't. Some people just are uncomfortable with calling Base.method(self, ...) and feel super is "more correct". Let them.
Here's another page that says much the same thing, but from the viewpoint of recommending the use of super and showing you all the hoops to use it right: http://wiki.osafoundation.org/bin/view/Chandler/UsingSuper
The problem isn't caused by super but by multiple inheritance.
James
PS, I wrote that page last pycon but never got around to finishing it up and therefore never really publically announced it. But I told some people about it and then they kept asking me for the URL so I linked to it, and well, then google found it of course, so I guess it's public now. ;)
Doesn't mean you can't fix it. :)
-- --Guido van Rossum (home page: http://www.python.org/~guido/)
- Previous message: [Python-Dev] Re: super() harmful?
- Next message: [Python-Dev] Re: super() harmful?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]