DMD 0.177 release

Boris Kolar boris.kolar at globera.com
Tue Dec 12 05:22:11 PST 2006


== 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.

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).

I'm in favour of allowing programmer to mark special semantics, such
as value class, or pure function (without side effects). Many additional
optimizations can be performed under such assumptions. Most notably:
value classes could be destroyed predictably (without causing arbitrary
long GC pauses) and calls to pure functions with unchanged parameters
can be cached (for example, foo.name().length()...). Also, it would be
interesting to mark some functions as compile-time, requiring that
they only interact with values that are known in compile-time. This
would make metaprogramming much more similar to normal programming.
One additional nice thing: you can support such declarations even
before optimizer takes advantage of them.

Also, I would suggest issuing a compile-time warning when polymorphism
is used without explicit 'override' directive. Perhaps coupled with a
pragma or something to turn such warning off.

PS: I really appreciate all the work that has been put in D. D is going
to be a much needed successor of C++. I don't see D as competitor to
Java or C# (I think that when using .NET or JVM is an option, D would
be a terrible choice), but it sure can rock the non-VM world!



More information about the Digitalmars-d-announce mailing list