Why isn't multiple inheritance very useful?

J

Joseph Turian

Why do people asked loaded rhetorical questions in the most innocent
manner possible?
 
H

Howard

Vla said:
why did the designers of c++ think it would be more useful than it turned
out to be?

I don't know. Want me to ask them? I've got their cell phone numbers here
somewhere... :)

-H
 
V

Vla

Joseph Turian said:
Why do people asked loaded rhetorical questions in the most innocent
manner possible?

Whether true or not, it certainly is, or at least was, a widely held belief,
that multiple inheritance doesn't turn out to be of much practical use.
Perhaps in the couple years since I last heard that (or read it) "modern c++
design" has evolved to include widespread use of multiple inheritance. My
question would then become "why did it take so long for multiple inheritance
to catch on".

Unless you want to deny that multiple inheritance was ever considered to be
a slight disappointment regarding its practical use.
 
T

Thomas Matthews

Vla said:
why did the designers of c++ think it would be more useful than it turned
out to be?

Multiple inheritance is very useful.
Beware the Diamond pattern.
Read the FAQ about inheritance.
Consult "Design Patterns" about multiple inheritance.

--
Thomas Matthews

C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq: http://www.parashift.com/c++-faq-lite
C Faq: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.learn.c-c++ faq:
http://www.comeaucomputing.com/learn/faq/
Other sites:
http://www.josuttis.com -- C++ STL Library book
http://www.sgi.com/tech/stl -- Standard Template Library
 
R

red floyd

Vla said:
[redacted]
Whether true or not, it certainly is, or at least was, a widely held belief,
that multiple inheritance doesn't turn out to be of much practical use.

And in years past, it was a widely held belief that the world was flat.
Your point?

Read the book "Modern C++ Design", by Andrei Alexandrescu to see what
Victor was talking about.
 
A

Andy

I don't know. Want me to ask them? I've got their cell phone numbers here
somewhere... :)

-H

its funny how ppl just insult others or try to be funny because they dont
like the question they asked. The guy asked a question if you dont know
the answer are feel its stupid then dont reply to it.
 
Z

Zorro

I am not sure whether you guys are joking, or these are serious
concerns. Multiple inheritance is not possible for virtual machines
with the technology underlying Smalltalk, Java and C#. It is easy to
see who spreads the word that multiple inheritance is complicated. The
question is, who is it complicated for? The designer of the language or
the engineer?

There are many ordinary problems whose implementation becomes
excessively long, and far from the intuitive view of the problem when
one is forced to use single inheritance.

You can find a superset of C++ running on a tiny virtual machine. Visit
www.zhmicro.com

Enjoy it.
 
G

Gianni Mariani

Vla said:
why did the designers of c++ think it would be more useful than it turned
out to be?

Why do you think the designers of c++ thought it would be more useful
than it is ?

BTW - If I was a C++ designer, and I thought back then that multiple
inheritance would be as useful as I now think it is, I'd be quite happy
with myself.

G
 
M

matthias_k

Vla said:
why did the designers of c++ think it would be more useful than it turned
out to be?

I think it -is- very useful. I'm not sure who the people are telling you
it wouldn't be useful. Probably Java enthusiasts. In fact, the lack of
multiple inheritance in Java can be an annoyance, because you have to
workaround using interfaces and delegation. It makes your code slower,
but you end doing the same thing basically.

By the way, multiple inheritance doesn't even need to be as error prone
as a lot of people claim. Look at Eiffel or Sather or Objective C, they
have pretty clever mechanisms to deal with multiple inheritance.

Regards,
Matthias
 
A

Andreas Huber

Zorro said:
It is easy to
see who spreads the word that multiple inheritance is complicated. The
question is, who is it complicated for? The designer of the language
or the engineer?

That question could prove more difficult to answer than one might think.
Interface-style MI as supported by Java & C# surely makes things easier
for language designers and the people who actually implement the
language. However, a nice side-effect is that easier implementations
also often perform much better. Specifically, garbage collectors and
casts are faster in the absence of full MI and that also benefits the
language users.
There are many ordinary problems whose implementation becomes
excessively long, and far from the intuitive view of the problem when
one is forced to use single inheritance.

Right. However, both the Java and the CLR/C# teams felt that performance
is more important than a releatively rarely used language feature,
which - given that you control the code of all classes you want to
inherit from - can easily be simulated with intefaces.

Regards,
 
S

Stewart Gordon

Vla said:
why did the designers of c++ think it would be more useful than it turned
out to be?

I'm not entirely sure what you mean, and anyway your subject and body
ask two quite different questions.

ATMS, multiple inheritance is a relatively complex feature. As such,
some languages have decided not to include full MI, but offer such
partial solutions as interfaces and mixins. This was part of the design
of D:

http://www.digitalmars.com/d/overview.html

"Features to Drop"
"Multiple inheritance. It's a complex feature of debatable value. It's
very difficult to implement in an efficient manner, and compilers are
prone to many bugs in implementing it. Nearly all the value of MI can be
handled with single inheritance coupled with interfaces and aggregation.
What's left does not justify the weight of MI implementation."

As for why MI was included in C++, maybe it was a matter of believing
that it might come in useful one day, rather than having any particular
practical uses in mind. And eventually people found uses.

Now that some languages provide these partial solutions, there is more
scope for debate over MI's usefulness.

Stewart.
 
P

Pete Becker

Zorro said:
Multiple inheritance is not possible for virtual machines
with the technology underlying Smalltalk, Java and C#.

Well, maybe in the sense that these VMs weren't desiged to support
multiple inheritance. But that's a design decision, not an inherent
limitation. This reminds me of the assertion I once saw in a Java
magazine that C++ couldn't have garbage collection because it doesn't
run in a VM. The two have nothing to do with each other. (Our compiled
Java implementation doesn't run in a VM, but it does have garbage
collection).
 
S

Stewart Gordon

Pete Becker wrote:
Well, maybe in the sense that these VMs weren't desiged to support
multiple inheritance. But that's a design decision, not an inherent
limitation. This reminds me of the assertion I once saw in a Java
magazine that C++ couldn't have garbage collection because it doesn't
run in a VM. The two have nothing to do with each other. (Our compiled
Java implementation doesn't run in a VM, but it does have garbage
collection).

The same applies to GC languages that were designed to be complied into
native code. D is one; can anyone think of others?

http://www.digitalmars.com/d/

Not to mention that GC engines have been written for C++. The trouble
is that, since C++ wasn't designed with GC in mind, C++ libraries don't
tend to get on well with GC engines.

Stewart.
 
W

White Wolf

Stewart said:
Pete Becker wrote:


The same applies to GC languages that were designed to be complied into
native code. D is one; can anyone think of others?

There are a billion, they just get less hype than D. xBase++ was one of
them, but I am sure there are many others.
 
J

Jerry Coffin

[ ... ]
The same applies to GC languages that were designed to be complied into
native code. D is one; can anyone think of others?

Oh, let's see: ML/SML, Algol68, Modula III, Eiffel (after "freezing"),
BASIC (GC only on strings), a multitude of LISP variants, Simula,
several SNOBOL 4 variants (e.g. Fastbol), Icon, Haskell, Sather (at
least sometimes does native compilation, though I'm not sure about
whether it was really designed with that in mind), etc., ad off-topic
naseum.
 
Z

Zorro

Andreas, there is a lot of truth in your statements. But think about
this.
Java does not have enumeration type. It turn out that one actually
needs it. So, in Java one turns a class into a global namespace by
declaring everything in it as static. That simulates enumeration.
However, just because one has MI available, it does not mean that one
should use it where it makes no sense. But when it is needed,
simulating it is awkward, just as simulating enumeration is.
Regards,
Z.
 
Z

Zorro

Yes Pete, it was a natural design decision for Smalltalk language based
on the idea used to implement its stack machine. The design here is
that a super class will be the base for everything.
So now the question for Java is this. Did they first research the
language and its suitability for expressing problems, and then they
made the VM, or, from what they could do with VM, they put a language
together?
As for garbage collection, it is not easy to just say a few things
about pointers and make much sense. However, Java garbage collection is
a consequence of yet another difficult issue. Have you noticed that all
interpreted languages, and those running on VM do not have pointers? It
is a lot easier to do garbage collection, and then make a big deal
about it.
The use of pointers is extremely difficult. But then, should we trust a
truck driver to fly a plane, or vice versa? So every engineer has
his/her favorites and experience.

Regards,
Z.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,563
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top