Multiple subtyping with alias this and nested classes
Andrei Alexandrescu
SeeWebsiteForEmail at erdani.org
Sat Oct 3 10:03:31 PDT 2009
Leandro Lucarella wrote:
> 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).
Alias this was introduced purposedly to allow multiple subtyping. Until
yesterday, however, I hadn't realized how much nested classes help with
that. Even before that I wasn't worried, since MI designs are not as
frequent as SI designs.
>> 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 :)
I don't see using a nested class (or any class) with alias this as a
hack. It's the way the whole thing is supposed to work in the first place.
>> Scala supports that with mixins, D supports that with multiple
>> subtyping.
>
> I don't know what you mean about multiple subtyping.
You subtype once by using inheritance, and then some more by using alias
this.
Andrei
More information about the Digitalmars-d
mailing list