3 ms·
His argument against inheritance seems based largely on Python's weak implementation of private attributes. I mean, maybe he has an argument against inheritanc
by aetherson 9y ago
His argument against inheritance seems based largely on Python's weak implementation of private attributes. I mean, maybe he has an argument against inheritance in Python, or some versions of Python.
But if the only argument you have against inheritance is "private names may collide," well, like, computer science has you covered, dude.
- stinos 9y agoThis. I expected a whole bunch of arguments against it (not that I haven't read all of them before) but the It’s a bad way for two layers of a system to communicate because it leaves each layer nowhere to put its internal state that the other doesn’t need to know about. argument is indeed kinda weak given that exact problem is solved in other laguages, so can in my opinion not really be used to prove the more general statement 'inheritance is bad'.
- ubernostrum 9y agoHis argument against inheritance seems based largely on Python's weak implementation of private attributes. No, it seems like a Python-based example of one of the well-known problems with inheritance, which applies even in languages like Java and C++ with explicit compiler-enforced visibility modifiers. Difficulty determining which class in a hierarchy is responsible for a particular member is not only a Python problem, or an "only languages without explicit public/private/protected" problem. One reason why composition is favored -- and remember, "composition over inheritance" goes back to the GoF book and earlier! -- is clearing this up. Of course, blindly "composing" is also bad, which is what this post points out.
- pseudalopex 9y agoYou're right that visibility modifiers don't solve the general problem, but the author specifically says "Inheritance is bad... because it leaves each layer nowhere to put its internal state".
- pseudalopex 9y agoThe author's argument is the Python equivalent of "protected isn't private". A.__note and B.__note wouldn't collide.