[D.typesystem] Suggestion for improving OO inheritance models

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Wed Sep 1 15:03:05 PDT 2010


On 9/1/10 16:56 CDT, retard wrote:
> Wed, 01 Sep 2010 23:30:08 +0200, Jacob Carlborg wrote:
>
>> On 2010-09-01 22:44, Philippe Sigaud wrote:
>>> On Wed, Sep 1, 2010 at 18:13, retard<re at tard.com.invalid>  wrote:
>>>
>>>
>>>      Have you taken a loot at Scala&  traits already? It would be a
>>>      great starting point.
>>>
>>>
>>> Scala's traits are great! Implicits in Scala are quite interesting too.
>>> Also, Haskell typeclasses
>>>
>>> I wonder if D can have part of Scala traits functionality with mixins?
>>
>> You can't use D template mixins to add methods that will overload
>> existing methods.
>
> I'm afraid D's template mixins are like a poor man's copy/paste macro
> system. Scala's approach takes subtyping into account. D 2 took a step
> towards traits actually since it allows some implementations&  contracts
> in interfaces. However, Scala is more flexible. Scala's design had the
> focus on nice OOP properties the whole time, but D will probably only get
> features if implementing them efficiently is a low hanging fruit.

I agree. Traits are my favorite feature of Scala and probably the main 
modeling advantage that Scala has over D and other languages. A 
carefully designed feature for the win.

Scala-style mixins aren't very difficult to implement for D, but I'm not 
sure if something like this would happen soon.


Andrei



More information about the Digitalmars-d mailing list