Multiple Inheritance of Classes

superdan super at dan.org
Tue Aug 12 07:26:24 PDT 2008


Lars Ivar Igesund Wrote:

> Chris R. Miller wrote:
> 
> > Understand, I'm NOT demanding ANYTHING.
> > 
> > What is the current state of thought about Multiple Inheritance for
> > classes in D?  I'd like to have that feature, since it'd make some stuff
> > I want to do a bit easier.  Is it not there because it's not worth the
> > effort to implement?  Because it's evil and needs to die (I don't know,
> > some people could possibly be adamantly anti-MI)?  
> 
> This is actually the reason, not the adamantly anti-MI part, just that MI is
> evil and that is well acknowledged almost everywhere. You will find good
> argumentation against it if you look, too.

appeal to authority. appeal to ridicule. appeal to the majority. all in one sentence. wow. at least could you space out your fallacies a bit more.

the man has kindly asked a sensible question. he deserves a good answer. if u can't give one just don't reply. this is just ignorance.

below's an attempt at an answer.

first i repeat what is already known. d does do multiple inheritance thru interfaces. it doesn't do multiple inheritance of implementation. better put doesn't do multiple inheritance of data. why? simple. d is a fixed layout language. means that the offset of any data member within the object is known during compilation. with mi it is impossible to lay out objects in a fixed layout. unless you do it the nonsensical way c++ does. at least you can't lay out with 1-dimensional memory. (i've done vlsi design and sure as shit 2-dim helps a lot. but a lot more could be done with 3-dim. i remember only adding two layers was a huge deal.) with mi from n classes you'd need n-dimensional ram. that's why only simple inheritance is possible with 1-dimensional ram. if u want fixed layout that is. (now that i got into it there was a guy who did 2-class inheritance by storing stuff at positive and negative offsets, thus adding a 2nd dimension.) mi of interfaces is a good thing and putting an int in an interface does not make it evil. just makes it impossible to lay out.

interfaces could implement functions. that does make a lot of sense. example:

interface Customer
{
    string ssn();
    string name();
    string uniqueName() { return name ~ "(ssn: " ~ ssn ~ ")"; }
}

so uniqueName formats a specific way. a descendant can choose to change that or just use the default. no idea why walt chose to disallow that. walt? 

> > I don't know.  I know 
> > I can add a lot with mixins, but I'd just like to know what the state of
> > the feature is.
> > 
> > The reason is I was trying to explain how cool D is to some other
> > friends of mine, and they asked about Multiple Inheritance (of classes)
> > and they were sort of put off by it's lack of it.  Then again, he was an
> > Objective-C programmer...  ;-)
> 
> In the languages where MI is possible, it usually also is possible to not
> shoot your own foot with some care, in which case it can appear as a
> powerful feature. But almost everywhere it just is a very bad idea, and you
> will find it is banned in many projects for languages allowing it (like
> C++).
> 
> > So please don't take offense, since none is meant, I just wanted to know
> > what I could hope for in the future.
> 
> You should hope you can redesign your application to not need MI ;)
> 
> -- 
> Lars Ivar Igesund
> blog at http://larsivi.net
> DSource, #d.tango & #D: larsivi
> Dancing the Tango

"blah blah blah more contentless uninformative fallacious blabber blah i can't believe i'm still reading this blah blah". sorry dood but this is all i'm seeing.




More information about the Digitalmars-d mailing list