[linux-elitists] Nobody's favorite language? C++ and free software
Tue Mar 25 15:14:35 PST 2003
On 25 Mar 2003, Don Marti <email@example.com> wrote:
> Is it my imagination, or is the number of useful free software
> projects in C++ on the rise? (I'm partly going by my Linux Journal
> inbox here.)
> For example, Xerces and Xalan at apache.org are in C++.
My very vague memory is that they began from code donated by Sun (?)
so they're not really represented of a native-born free project.
I think the reason it's not popular is that C++ is a poor tradeoff
between C and higher-level languages (Java, Python, Perl, Ruby, ...)
You have difficulties of C like possible memory corruption, no
(standard) garbage collection, up-front compilation, etc. But you
don't have the advantages: it's the standard API for Unix and almost
every library; almost everybody knows it.
You don't have the advantages of higher-level languages, like being
able to generate or manipulate code at run time, use an interpreter,
deal with truly first-class objects, be approachable to novices, etc.
But you do have some of the problems: larger runtimes (at least in the
past), smaller audiences of programmers (at least in free unix),
needing to call through lower-level interfaces to get to libraries.
You can also look at Gabriel's "worse is better" for clues. C++ does
not have a "predictable performance model" in the way that C does: by
looking at C code, you can see roughly how many cycles it will take
(as a parameter of the inputs, anyhow.) That's not true for C++:
implicit constructors and similar things make it harder to see from
the code exactly what is going on.
A lot of the features that really should have been there from the
beginning (exceptions, standard libraries, gc, dynamic casts ...) came
later, and what's worse came out in several incompatible versions.
> 2. C++ is a Very Large Language
> K&R, The C Programming Language, 2nd ed. -- 274pp.
> Stroustrup, The C++ Programming Language, 3rd Special Ed. -- 1040pp.
> "It seems to me quite plausible that the complexity of the language adds
> to the time and cost of a full education in C++." -- Raph Levien
Not only this, but STL, Qt, and similar things introduce new concepts
that in other systems would be considered part of the language.
Really C++ is even larger than those numbers might make you think.
More to the point: why does *anyone* use C++?
I think the absolutely dominant reason is that the first really usable
development kit for Windows (circa 3.0) used C++: everything before
exported a low-level, poorly documented, and immature API. The
usability was partially due to switching to a slightly higher-level
language, but more so due to a credible effort by Microsoft to improve
the API and provide better help to programmers. C++ was there at the
right place and time to take the credit, much as Perl was for CGIs.
I suppose the main advantage of it is that you can directly call into
C programs and have the same optimization (or pessimisation)
opportunities as C, while having some OO help. But these days this is
largely countered by the great native-interface support in scripting
languages: you can equally well put the existing or
performance-critical C code behind a JNI or Python interface.
More information about the linux-elitists