
On 10/20/2015 03:40 PM, Chris Angelico wrote:
On Wed, Oct 21, 2015 at 5:14 AM, Sven R. Kunze <srkunze@mail.de> wrote:
Not saying that inheritance is a bad thing but to me It seems to me that ordering and default values should be orthogonal aspects of the standard dict.
Just as Sandi described it here: https://www.youtube.com/watch?v=29MAL8pJImQ
Yeah... that video is absolutely correct... for Ruby. In Python, you can use multiple inheritance to do that in the exactly obvious way.
class EchoRandomHouse(EchoHouse, RandomHouse): pass
When I got to the bit in that video where she says that inheritance paints you into a corner, I went and reimplemented her example code in Python, and it's flawless. It doesn't even matter which order you put the two superclasses, as there's no conflict.
I think you missed her real point, which applies both to Python and Ruby. In her presentation, it's obscured a bit by too much discussion of "one side or the other" code duplication (which can be "solved" with multiple inheritance). It takes her a couple minutes more to get to the real point, which starts at the slide "inheritance is for specialization, not for sharing code." One symptom of the problem is that using multiple inheritance this way doesn't scale: the number of leaf subclasses you need grows geometrically with the number of behavior knobs. Composition with strategy objects doesn't have this issue. Carl