News for hackers. Stuff that matters.
Re:OOP Is Dead, Long Live OOP by jcelerier on Thursday October 18, 2018 @03:45PM (#18251496)
> Sure, the general consensus is that inheritance is better achieved through composition.

This sentence does not make sense. If you want to have a class composed of two other classes, whose behaviour is defined at run-time - say, a generic "Engine" object which is composed of a "GraphicsRenderer" and an "AudioRenderer" where the first one can be a D3D renderer or an OpenGL renderer and the second can be an XAudio or OpenAL renderer, you have to have inheritance somewhere, because you have to store at least one function pointer at some point. std::function in C++ is implemented with inheritance. Rust traits are based on inheritance. However you look at it, you can never completely "get rid" of inheritance if you want to hide both code and data behind a single pointer. Hell, even the linux kernel written entirely in C reimplements vtables by hand for device drivers because it makes so much sense.

Re:OOP Is Dead, Long Live OOP by hota_mazi on Thursday October 18, 2018 @03:54PM (#18251574)
You are confusing inheritance of implementation with inheritance of interface.

The consensus is to use inheritance of interfaces and use composition to implement the interfaces.

Hence my phrasing: "Inheritance is better achieved through composition".

Re:OOP Is Dead, Long Live OOP by marcosdumay on Thursday October 18, 2018 @06:41PM (#18252848)
> The consensus is to use inheritance of interfaces and use composition to implement the interfaces.

A consensus by the "maximization of boilerplate" rule.

Inheritance is the most powerful tool available at the OOP land. It's the one thing that FP languages still didn't replace with enough added advantages to make the OOP stuff look like a toy. So if you are programming in OOP while avoiding inheritance, you would be certainly better in another paradigm.

(And, of course, powerful tools are easy to misuse. That's no reason for forbidding them.)

Re:OOP Is Dead, Long Live OOP by mercer on Sunday October 21, 2018 @06:48AM (#18267454)
I'm not familiar enough to have a strong opinion on this, but the impression I get is that even the OOP camp (or thought leaders within those camps) seems to have abandoned inheritance in favor of composition.

Assuming this is the case: why do you disagree and what do you think is the cause of this difference in opinion?

Re:OOP Is Dead, Long Live OOP by CMCDragonkai on Friday October 19, 2018 @07:17AM (#18255825)
Check out extensible records or Nix language fix pattern for its attribute sets.
Re:OOP Is Dead, Long Live OOP by jcelerier on Thursday October 18, 2018 @04:43PM (#18251944)
But you still use the OOP concept of inheritance, which is basically "indirect methods with function pointers". Beside, "interfaces" don't even exist as a syntaxic concept in many OOP languages, C++ being the most prominent one.
Re:OOP Is Dead, Long Live OOP by munchbunny on Thursday October 18, 2018 @06:51PM (#18252907)
That's splitting hairs. Regardless of the syntax mechanism used to achieve it, inheritance of interfaces and inheritance of implementation are qualitatively different, in the sense that you can usually tell the difference regardless of language.

Also, C++ has abstract classes with only pure virtual functions, which accomplish the same thing.

Re:OOP Is Dead, Long Live OOP by spdionis on Thursday October 18, 2018 @06:32PM (#18252782)
I think C++ is the only one that doesn't have interfaces.
Re:OOP Is Dead, Long Live OOP by maxxxxx on Thursday October 18, 2018 @08:07PM (#18253395)
An abstract class with only abstract methods is essentially the same.
Re:OOP Is Dead, Long Live OOP by jcelerier on Friday October 19, 2018 @07:57AM (#18256032)
It's most certainly not:

- you have to at least implement the destructor if you are going to use the abstract class across multiple DLLs - else, dynamic_cast won't work since each DLL may have its own type_info object for the abstract class

- even if a method is marked abstract, it can still have a default implementation: https://gcc.godbolt.org/z/bAE7v6 though other prominent OO languages are slowly catching up with this ;)

Re:OOP Is Dead, Long Live OOP by spdionis on Thursday October 18, 2018 @06:32PM (#18252776)
extends != implements