Multiple subtyping with alias this and nested classes

Leandro Lucarella llucax at gmail.com
Sat Oct 3 09:52:51 PDT 2009


Andrei Alexandrescu, el  3 de octubre a las 11:23 me escribiste:
> Leandro Lucarella wrote:
> >Andrei Alexandrescu, el  2 de octubre a las 19:10 me escribiste:
> >>Leandro Lucarella wrote:
> >>>We might have very different taste, but I find that a little... horrible.
> >>>What do you have against mixins? I think you're trying to use D as C++ :)
> >>If mixins work better, all the better. How would you use them to
> >>achieve multiple inheritance?
> >
> >Don't design with multiple inheritance in mind, use interfaces + mixins
> >for common functionality instead.
> 
> But you're just saying it. I think you'd agree I wouldn't just
> follow that dogma noncritically just because you told me what to do.

No, because the language is designed to do that AFAIK, so it will be much
easier and clear (for who writes the code and who reads it). I think you
hack with alias this is more obscure (we might be hitting personal taste
here, I grant you that).

> I don't think many people design with multiple inheritance in mind.
> They design aiming at a good design.

But you always have to take into account the tools you have when
designing. What's the point of designing a perfect bridge assuming you
have a material that doesn't exist?

Of course you can do that, but when you hit reality, you'll have to "hack"
your design to fit your real tools. So you can design something that
"looks like" multiple-inheritance, because it's easier (or nicer) to do
so. But when you want to put that in reality, you have to choose what tool
to use. In C++ you probably want to use MI (because the language has
a good support for it), but in D you probably want to use interfaces
+ mixins (because the language has good support for it).

Of course you can even implement it in C, or even assembly; you can
implement it as in C in C++ or D too, but it would be harder and more
obscure.

> In my experience, some designs can make gainful use of multiple
> inheritance of classes, and some of my best designs do use multiple
> inheritance simply because it was the best tool for the job.

Sure, the problem comes when the language don't support MI ;)

So, there we are, you have D, which doesn't support MI per se, you have to
hack it. You can do it with the nested-inherited-classes+alias-this hack,
or by using interfaces+mixins. We agree at least that you have the same
result with both right? Then, I guess is just a matter of taste. I simply
find much more obscure and complex the nested-inherited-classes+alias-this
hack than interfaces+mixins :)

> Scala supports that with mixins, D supports that with multiple
> subtyping.

I don't know what you mean about multiple subtyping.

-- 
Leandro Lucarella (AKA luca)                      http://llucax.com.ar/
----------------------------------------------------------------------
GPG Key: 5F5A8D05 (F8CD F9A7 BF00 5431 4145  104C 949E BFB6 5F5A 8D05)
----------------------------------------------------------------------
I am so psychosomatic it makes me sick just thinking about it!
	-- George Constanza



More information about the Digitalmars-d mailing list