June 22, 2021

On Tuesday, 22 June 2021 at 09:04:05 UTC, IGotD- wrote:

>

It's because the diamond problem. The diamond problem is purely an academic problem and it very seldom happens in the real world and if it does you probably did something wrong in your design. Happen to me once in 30 years because I messed up. Multiple inheritance is often flat, which means that one class inherits from several others at the same level. Instead of disallow multiple inheritance you can disallow the diamond pattern.

It is usually best to not use multiple inheritance, but it would be better for the D eco system if D classes map to C++ since they are so close anyway.

June 22, 2021

On Tuesday, 22 June 2021 at 09:04:05 UTC, IGotD- wrote:

>

[snip]

It's because the diamond problem. The diamond problem is purely an academic problem and it very seldom happens in the real world and if it does you probably did something wrong in your design. Happen to me once in 30 years because I messed up. Multiple inheritance is often flat, which means that one class inherits from several others at the same level. Instead of disallow multiple inheritance you can disallow the diamond pattern.
[snip]

Some other language had suggested something like below as a solution to the diamond problem
class A { void a() {} }
class B : A {}
class C : A { @disable a; }
class D : B, C {}

However, I was thinking what happens if you do something like
A ac = new C();

How would the compiler handle that?

June 22, 2021

On Tuesday, 22 June 2021 at 02:13:33 UTC, zjh wrote:

>

On Monday, 21 June 2021 at 19:56:50 UTC, Meta wrote:

You can check inheritance conflicts at compile time.
Once the conflict method is used, the full name is required, otherwise it cannot be compiled.

June 22, 2021

On Tuesday, 22 June 2021 at 11:13:52 UTC, jmh530 wrote:

>

However, I was thinking what happens if you do something like
A ac = new C();

How would the compiler handle that?

Runtime error, but this is just a bad idea.

If B and C inherits from A and specializes a() then a D that inherits from both B and C should be forced to implement a().

Not really a big issue, I think.

June 22, 2021

On Tuesday, 22 June 2021 at 11:13:52 UTC, jmh530 wrote:

>

On Tuesday, 22 June 2021 at 09:04:05 UTC, IGotD- wrote:

>

[snip]

It's because the diamond problem. The diamond problem is purely an academic problem and it very seldom happens in the real world and if it does you probably did something wrong in your design. Happen to me once in 30 years because I messed up. Multiple inheritance is often flat, which means that one class inherits from several others at the same level. Instead of disallow multiple inheritance you can disallow the diamond pattern.
[snip]

Some other language had suggested something like below as a solution to the diamond problem
class A { void a() {} }
class B : A {}
class C : A { @disable a; }
class D : B, C {}

However, I was thinking what happens if you do something like
A ac = new C();

How would the compiler handle that?

That language is called Eiffel, and in such case, C become abstract class, as I explained in this post:

https://forum.dlang.org/post/ztawxnwydbxiymcqvzhr@forum.dlang.org

https://forum.dlang.org/post/ztawxnwydbxiymcqvzhr@forum.dlang.org

June 22, 2021

On Tuesday, 22 June 2021 at 09:04:05 UTC, IGotD- wrote:

>

On Tuesday, 22 June 2021 at 02:13:33 UTC, zjh wrote:

>

multiple inheritance is very good.I dont know why they are objective.
10+ years ago,they refuse to listen others' suggestion.
I dont know if they still refuse now.

It's because the diamond problem. The diamond problem is purely an academic problem and it very seldom happens in the real world and if it does you probably did something wrong in your design. Happen to me once in 30 years because I messed up.

Forgive me to repeat: diamond problem is a solved problem, elegantly by Eiffel, see my previous post, and example on github:

https://forum.dlang.org/post/deeuyrcwxjkjerpgqdjj@forum.dlang.org

>

Multiple inheritance is often flat, which means that one class inherits from several others at the same level. Instead of disallow multiple inheritance you can disallow the diamond pattern.

D went another way with composition with template mixins. Nothing particular wrong with this model but I think the D documentation isn't clear about its intended use. Also the overlap with alias this makes it more confusing.

June 22, 2021

On Tuesday, 22 June 2021 at 13:42:30 UTC, mw wrote:

>

[snip]

>

However, I was thinking what happens if you do something like
A ac = new C();

How would the compiler handle that?

That language is called Eiffel, and in such case, C become abstract class, as I explained in this post:

https://forum.dlang.org/post/ztawxnwydbxiymcqvzhr@forum.dlang.org

https://forum.dlang.org/post/ztawxnwydbxiymcqvzhr@forum.dlang.org

Thanks, the name of the language wasn't coming to me but I recall the prior discussion.

So if C becomes abstract, then the above line is prevented because you cannot instantiate an abstract class (correct? I can't test it on run.dlang.org right now and I'm not sure if it is C c = new C() that is prevented or this one). That's kind of limiting, no?

Does that have any separate implications for:

A ad = new D();
B bd = new D();
C cd = new D();
D dd = new D();

My thought would be that just cd would be prevented.

June 22, 2021

On Tuesday, 22 June 2021 at 14:54:42 UTC, jmh530 wrote:

>

On Tuesday, 22 June 2021 at 13:42:30 UTC, mw wrote:

>

[snip]

>

However, I was thinking what happens if you do something like
A ac = new C();

How would the compiler handle that?

That language is called Eiffel, and in such case, C become abstract class, as I explained in this post:

https://forum.dlang.org/post/ztawxnwydbxiymcqvzhr@forum.dlang.org

https://forum.dlang.org/post/ztawxnwydbxiymcqvzhr@forum.dlang.org

Thanks, the name of the language wasn't coming to me but I recall the prior discussion.

So if C becomes abstract, then the above line is prevented because you cannot instantiate an abstract class (correct? I

That's right.

>

can't test it on run.dlang.org right now and I'm not sure if it is C c = new C() that is prevented or this one). That's kind of limiting, no?

Not at all. First it's by the programmer's design (if s/he chooses to do it in this way).

Second: to solve diamond problem, undefine / rename a feature usually happen in D:

Class D : B(disable a), C {} // so using C.a()

Class D : B, C(disable a) {} // so using B.a()

Note: this resolution in D, make A B C D all usable, non of them is abstract.

Please check my github example.

>

Does that have any separate implications for:

A ad = new D();
B bd = new D();
C cd = new D();
D dd = new D();

My thought would be that just cd would be prevented.

In your example, yes.

June 22, 2021

On Tuesday, 22 June 2021 at 15:14:02 UTC, mw wrote:

>

[snip]
Not at all. First it's by the programmer's design (if s/he chooses to do it in this way).

Second: to solve diamond problem, undefine / rename a feature usually happen in D:

Class D : B(disable a), C {} // so using C.a()

Class D : B, C(disable a) {} // so using B.a()

Note: this resolution in D, make A B C D all usable, non of them is abstract.

Please check my github example.
[snip]

Thanks for the reply.

The only github example I could find was in Eiffel

https://github.com/mingwugmail/dlang_tour/tree/master/eiffel/mi

Is that the right one?

June 22, 2021

On Monday, 21 June 2021 at 13:40:42 UTC, Ola Fosheim Grøstad wrote:

>

What prevents unifying D classes with C++?

https://www.amazon.com/Inside-Object-Model-Stanley-Lippman/dp/0201834545

There are books dedicated to explaining the C++ object model, so sure, let's emulate that!