C++ (was RE: Python suitability)

Alex Martelli Alex.Martelli at think3.com
Wed Dec 15 04:30:55 EST 1999


Grant writes:

> About twice as long as it would take for a Modula-3 or
> Smalltalk programmer.  ;) I've never thought C++ was a
> particularly decent example of an object-oriented language, but
> maybe that's because I learned Smalltalk and M3 first.
> 
> The whole virtual-function-method thing has always struck me as
> very obtuse.  You apparently have to guess ahead of time which
> methods somebody might, at some point in the future, want to
> override, and declare them differently from the non-overridable
> ones...
> 
Or, to put it another way: you have to DESIGN, rather than
just start hacking.

Specifically, if you follow the advice of Scott Meyers, in his
excellent "Effective C++" (CD Edition): never inherit from a
concrete class.

If you do all of your inheritance from abstract classes, and
use better (although somewhat more boilerplatey:-) schemes
for code reuse (mainly containment-and-delegation -- I just
wish C++ had a smooth way to express delegation, sigh),
you're _forced_ to design-rather-than-hack -- which is one
big plus -- and you get better componentization, modularity,
and scalability (cfr Lakos' "Large Scale C++" -- what he
calls "protocol classes" are exactly abstract classes, or Java
"interface"'s if you wish; cfr Martin's books, and the papers
on his side -- his "dependency inversion" transformation
is one way to refactor a design with bad dependencies, and
it does so by introducing inheritance-from-abstract-classes).


I'm not surprised that a Python enthusiast may not appreciate
C++'s basic underlying philosophy, since it's so close in many
surprising respects to Perl's -- reading Larry Wall's musings on
his language, and Stroustrup's on his own, side by side, can
be very enlightening in this respect, more than the huge surface
differences between Perl and C++ might lead one to expect.

One key difference is that, in C++, you _can_ design and
maintain huge and flexible projects -- the language does not
hinder, and gives you almost all the tools you need for that
("almost": it misses language-level, standard support for such
key packaging/deployment issues such as packaging into
separate "libraries", threading and IPC issues, network
access, GUIs, DBs -- you have to turn to other standards
for these; on the plus side, C++, having no built-in idea of
how any of those should work, will never hinder you from
integrating with any other existing architecture you may need).

C++ does not _constrain_ you to do your homework, and
design (and design _well_) -- it does not even really make
any serious attempts at so constraining -- letting you do
just about anything means giving you by far "enough rope
to shoot yourself in the foot".  This means most developers
are NOT suited for the language (or vice-versa:-), because
they lack the professional discipline, or the skill to apply it
successfully, for the kind of projects for which C++ makes
sense (either HUGE ones, or ones with really, TRULY tight
constraints of performance, where every microsecond
does matter).

But I doubt any language would make such developers
truly more productive at such tasks of extreme difficulty.
I've seen quite a few try to, and none truly succeed.


I'd rather program in Python -- but if the tasks I'm doing
are not suited for Python (e.g., developing components
which need to run EXTREMELY fast), then C++ is what
I'm happiest with.


Alex





More information about the Python-list mailing list