Re: Why C++ is vastly superior to C
Michael Doubez <michael.doubez@free.fr> writes:
OOP: bind as /late/ as possible
C++: bind as /early/ as possible (generic programming)
Are you talking about "name binding" vs "early bound method call" or
"compile time" vs "run time" ?
?Late? means to me: the decision which function body to call
is made depending on the run-time type of the participating
objects. (I guess, I would also have to require multimethods,
then. But multimethod lookup also has its drawbacks [complexity].)
Run-time polymorphism is possible in C++ (at least for one
object in an expression), but the C++ standard library is
based on templates. (I have not yet studied whether this
makes OOP harder in C++.)
In a real OOP language, like Smalltalk, blocks of statements
are also objects. This means, for example, one can define an
if method (in Smalltalk) as a method taking a boolean and a
block (of statements), then passing the block to the
boolean, where boolean objects of the class True execute
their blocks, while those of the class False do not. This
requires late binding, because the class of (x<y) is only
known as late as at run time (it might be the subclass True
of the class Boolean or the subclass False).
In C++, ?if? is not a method at all, but a keyword
hard-coded in the programming language. (Possibly, in
Smalltalk, if also is hard-coded. But it could be defined as
described in the preceding paragraph.)
But maybe C++0x is getting closer to Smalltalk and LISP with
its new closure objects!
I wonder how many times C++ is chosen for its performances;
do you have numbers ?
No, but since C++ is very complex, there must be some reason
to use in instead of languages more simple and secure, so
performance is a good candidate.