News for hackers. Stuff that matters.
Re:Goodbye, shitty Car extends Vehicle object-orientation tu... by tome on Saturday October 19, 2019 @02:28PM (#21299946)
> 3. Often you want to use the default protocol implementation with some changes. Instead of re-implementing the rest of the protocol, it's highly convenient to be able to specify only the differences.

> #3 is the core reason why inheritance was developed.

No, absolutely not. As sibling comments say, composition is sufficient for that. I can only see exactly one reason why inheritance is necessary: to allow superclasses to call methods defined in subclasses, also known as late binding.

Re:Goodbye, shitty Car extends Vehicle object-orientation tu... by colllectorof on Saturday October 19, 2019 @07:30PM (#21301351)
Firstly, late binding is orthogonal to inheritance. It simply means that methods are looked up based on runtime information, rather than determined at compile time. You can have late binding in a language with no inheritance or classes at all.

Secondly, OO composition does not solve the problem I described in #3. If object X has 9 methods I want to reuse in object Y, making X a component of Y still requires me to re-implement those 9 methods in Y, even if they are just pass-throughs.

Re:Goodbye, shitty Car extends Vehicle object-orientation tu... by couchand on Saturday October 19, 2019 @11:55PM (#21302230)
> If object X has 9 methods I want to reuse in object Y, making X a component of Y still requires me to re-implement those 9 methods in Y, even if they are just pass-throughs.

That is also not universal. In Ruby, for instance, one can write:

    class Y
      def method_missing(m, *args, &block)
        @x.send(m, *args, &block)
      end
    end
Re:Goodbye, shitty Car extends Vehicle object-orientation tu... by smrq on Sunday October 20, 2019 @02:42AM (#21302605)
I don't think you have to squint very hard to see that as an implementation of inheritance.
Re:Goodbye, shitty Car extends Vehicle object-orientation tu... by tome on Sunday October 20, 2019 @05:25AM (#21303078)
Will that allow the version of m in x to send messages back to y? I don't know Ruby, but most likely not.
Re:Goodbye, shitty Car extends Vehicle object-orientation tu... by kragen on Sunday October 20, 2019 @12:18PM (#21305058)
No, for that you need to pass a self argument. See my comment below about Abadi and Cardelli's book for a (reference to a) full development of the theme.
Re:Goodbye, shitty Car extends Vehicle object-orientation tu... by tome on Sunday October 20, 2019 @05:29AM (#21303091)
Actually, I shouldn't have made claims about "the core reason why inheritance was developed" because I've no idea why it was developed. On the other hand, I believe I know why it is necessary (as opposed to convenient). In many languages there is functionality it provides that is otherwise unavailable.

In Java, or C++, or Python, how can we allow superclass methods to call methods on a subclass (a form of late binding) without inheritance? I don't think it's possible. So unless I am much mistaken (and please correct me if I am wrong), inheritance is convenient for reducing boilerplate but necessary for late binding (in many languages).

Have I made a mistake in my analysis somewhere?

Re:Goodbye, shitty Car extends Vehicle object-orientation tu... by kd5bjo on Sunday October 20, 2019 @12:14PM (#21305034)
The “superclass” can take a config object with a well-defined interface in its constructor, and call methods on this config object when it might need to do something differently.
Re:Goodbye, shitty Car extends Vehicle object-orientation tu... by BubRoss on Saturday October 19, 2019 @11:27PM (#21302163)
He never said nothing else could accomplish the same thing, only that it was the reason it was invented.