Is this a true statement: Part II

Alex Martelli aleaxit at
Fri Jun 29 17:44:18 EDT 2001

"Paul Prescod" <paulp at> wrote in message
news:mailman.993843346.4433.python-list at
> > Why is C++ awful; what's wrong with it?
> C++ is a large and complex language. In my opinion it tries but fails to
> work both on the abstraction level of a high level language and a
> low-level language which gives it a very confusing runtime model. One

In my opinion it tries *AND SUCCEEDS* to work on both of these
abstraction levels, which is a good part of what gives it its complexity --
the real killer.  Mind you, I'll still use C++ by preference when I need
top performance -- it makes me much more productive than C (though
I don't know if it was worth the *many* years' worth of experience and
study to get to that level), not to mention Eiffel, Ada, and other B&D
languages, and (while I do enjoy FP in general -- Haskell is always a
pleasure) ML apparently just hits me wrong -- I'm not very productive
in it, and my ML code always seems to run slowly (particularly with
O'Caml, which is supposed to be the performance world-beater of the
FP world) -- presumably just some mental block on my part, but the
fact remains.  Oh, I'd still be good for writing some highly vectorizable
Fortran code if _those_ were the kinds of performance issues at hand,
I guess -- but they aren't, generally, and C++ lets me architect my
code's structure much better than Fortran (the Fortran I knew -- it
HAS been a while:-).

Besides, C++ enjoys excellent interfacing to Python -- only Java with
Jython is even better (but not in the performance arena:-)...

> minute you are doing things that look low-level but are really very
> computationally expensive and the next you are being constrained from
> doing something that seems reasonable because C++'s designers didn't
> want to take the performance hit.

After a few years and a few hundred thousands lines of code, you
gradually do get to internalize the various design decisions, at least
at this level.  As for "computationally expensive", there never was
any real alternative to profiling after-the-fact to find out where the
time is going... C++ is no worse than anybody else in this respect,
as it happens.

> Plus it is so complicated that the
> implementations still vary widely so you have to "port" code from one
> compiler to another.

That's one of the downsides of complication, yes.  Although the
common subset of (latest releases of) MSVC++, gcc and Comeau
(basically EDG front-end + a little glue to platform-specific
compilers, very cheap, very close to the ISO C++ Standard [for
the _language_ -- the _library_ is NOT there yet...]), covering
a vast majority of platforms, is close enough to the standard to
do a LOT of good work.  Porting among these three C++ compilers
(at least if using one common library, such as SGI's STL and
Boost) is no more "porting" than in my experience it was a few
years ago to port among the nominally-ISO-standard C compilers
of half a dozen major manufacturers.  (If the amount of '#if's in
Python's sources are a good indication, the difference between C
and C++ on this score isn't all that large -- considering the C
standard has been out for 12 years, the C++ one for 3, and the
latter is at least twice as big as the former, one would expect much
more problems in the C++ world compared with what one gets...).

My personal opinion, again: C++ is too complex for the human
mind (or, at least, mine) to grasp and use at perfect efficiency.
But, to paraphrase Churchill...: when you need top performance
in general-purpose tasks (particularly to write Python extensions),
it's the worst language there is... except only all others.

I think that over 90% of programmers would be better off it they
had never heard about C++.  But, there IS a need for top
performance -- in a tiny minority of the source code for a tiny
minority of the programs.  C++, particularly with templates
at their best ( for some examples), lets you get
top performance with coding that's still quite high-level.  It
bends your mind, surprises you once a week even if you're the
hardest-boiled guru around, and makes you curse (even when
you're not using the curses library) -- but it does deliver, when
used for what it's really well-suited for (MOST of what gets
coded in C++ today would be best coded in Python... but that
is another issue!-).

Alex (Brainbench MVP for C++ -- declaring interest, as it were:-)

More information about the Python-list mailing list