Noah said:
Markus Schoder wrote:
Similar as with non-virtual functions in C++ (yes I
A pretty big difference, no? non-virtuals in C++ can still be
overridden but that doesn't function polymorphically.
I know that it's something weird with C++. It is here mainly for
historical reasons, and should not be used.
So, IMHO, it is not a big difference... It's just a language trap.
Advanced programmers don't fall in, period.
You may say that it is a "huge flaw which totally spoils the language".
If you think so, then turn towards a more clean language. C++ is not a
"clean language designed from scratch". We have to live with it, and in
practice it is not a real problem when you know deeply the language.
It is a problem for teaching it to students, though.
In my opinion there shouldn't be any such thing as final or non-virtual
functions. I see the reasoning behind it in C++ where you can do
whatever you want and language features are 'removable' (like not using
polymorphism) but from a design standpoint I think it smells bad.
OOP is not the only programming paradigm... A huge number of problems
are better solved with another programming paradigm.
In particular, C++ accepts the object-based paradigm, which can be
easily and efficiently used, and doesn't require virtual functions.
And, in C++ you don't pay for what you don't use.
C++ gives the freedom of using any available programming paradigm you
want.
The overhead of a vtable pointer can itself be unacceptable when there
are a lot of small objects allocated.
For instance, a 1 or 2 bytes object may use 8 bytes (because of
vptr+alignment)!
Furthermore, objects such as std::vector would suffer from a huge
overhead (500% sometimes) for very simple inline operations such as
operator[].
Perhaps super-smart optimizers might more or less inline
false-virtual-calls at runtime, but such optimization were not
effectively possible in 1998 (and are still not perfect today).
Furthermore, it doesn't solve the space overhead problem.
C++ is a language efficient & implementable right now... It was created
for that purpose from the start : Be a language useful right now (in
the tradition of the C language).