DMD 0.177 release

Andrei Alexandrescu (See Website For Email) SeeWebsiteForEmail at erdani.org
Tue Dec 12 08:50:02 PST 2006


Boris Kolar wrote:
> == Quote from Walter Bright (newshound at digitalmars.com)'s article
> 
>>Andrei Alexandrescu (See Website For Email) wrote:
>>
>>>Classes are different from structs in two essential ways:
>>>
>>>1. Polymorphism
>>>2. Referential semantics
>>>
>>>The two are actually interdependent, as you can't have polymorphism
>>>comfortably unless you have reference semantics.
>>
>>That's one of the things I felt in my bones, but was unable to put my
>>finger on it.
> 
> 
> Actually, polymorphism does not imply referential semantics (nor does
> referential semantics imply polymorphism, of course).
> 
> 1) Value sematics can be achieved with references as well, by using
> copy-on-write strategy (or by making classes immutable). All that
> without sacrificing polymorphism.

Of course. It's a "true but uninteresting" fact. Even in current D you 
can think that int is a reference and that ++i rebinds i to another 
reference. But when talking about reference semantics, that means object 
is unique, references are many. Doing copy-on-write takes reference-ness 
out of references, so of course then they start behaving like value.

> 2) Polymorphism can be achieved without references as well, but then
> the size of struct could no longer be determined at comile-time. In
> other words, function 'sizeof' could no longer be parameterless. Or,
> alternatively, every such 'polymorphic struct' would have to contain
> two pointers: VMT and additional 'data' pointer (which is actually
> pretty close to using references anyway).

Yup, that's reference all right. Some Java implementations do this.


Andrei



More information about the Digitalmars-d-announce mailing list