Feedback on Átila's Vision for D

Meta jared771 at
Sun Oct 20 17:11:27 UTC 2019

On Sunday, 20 October 2019 at 09:31:34 UTC, Max Samukha wrote:
> On Saturday, 19 October 2019 at 22:14:55 UTC, Meta wrote:
>> It's not a defect. Interfaces have no state, so it doesn't 
>> matter which is called. Java does the same thing.
> What do you mean by 'have no state'? If Java does the same 
> thing, it does it wrong. Nominal typing is all about avoiding 
> structural conflicts. Members coming from different nominal 
> types should not be conflated.

Interfaces in D do not have any state, i.e., they're not allowed 
to declare member variables that implementing classes inherit, 
and they don't define any implementation for implementing classes 
to inherit - they just define the interface (this has recently 
changed in Java now that interfaces can define methods with a 
default implementation, thus Java now provides a way to 
disambiguate if two different interfaces declare default methods 
with the same name).

Because classes do not inherit any state or implementation from 
interfaces, if you have, say, the following class:

class ImplementsBoth: Display, Debug { void fmt(){} }

And you do `new ImplementsBoth().fmt()`, it really doesn't matter 
whether the fmt you're calling is Display's fmt, or Debug's, 
because there is no interface state or inherited implementation 
that would change fmt's behavior by calling one or the other.

The fact that interfaces carry no state or default implementaion 
is also why they don't have the diamond inheritance problem that 
C++'s multiple inheritance can cause.

So semantically, collapsing Display.fmt and Debug.fmt into one is 
perfectly valid. I agree it might be nice to allow disambiguating 
in certain cases, but that would be an enhancement, not a bug.

More information about the Digitalmars-d mailing list