
On Mon, Apr 04, 2022 at 07:17:55PM +1200, Greg Ewing wrote:
On 4/04/22 9:35 am, malmiteria wrote:
And just to make it clear, I am not under the impression super can only target one class. What i'm saying here is that it is the most common impression the average developper would have.
How do you know this? Have you undertaken a survey of randomly selected average developers?
I think that malmiteria is probably correct that most developers misunderstand or misuse super, or find it surprising. I know I do. Now matter how many times I remind myself that calling super().method is **not** the same as "call the method of my superclass", I still get surprised by how it actually works in the complicated cases. Simple cases (single inheritence) are fine. But I'm going to be brave, or possibly foolhardy, and say that when it comes to multiple inheritence, if you think you understand what super does in all the fine details, you're either superhuman or wrong :-) In SI, calling super() is effectively the same as calling the superclass, and its all fine. But in MI, calling super() can resolve to something unexpected. See malmiteria's Gobelin example. Now tell me that before you ran the code, or read my analysis of it, you would have predicted that super(ProudGobelin, self) would skip ProudGobelin's method and call CorruptedGobelin's method. I know I didn't. I think that where malmiteria gets it wrong is that he thinks that super is broken. Its not. But we might want to avoid MI, and use something like traits instead. Or composition. Changing super would be tantamount to banning MI, and that would be a massively backwards incompatible breaking change. It isn't going to happen (and nor should it happen, MI is fine for those who need it). -- Steve