Re: C++ in kernel (was Re: exception in a device driver)

Marc Espie (espie@quatramaran.ens.fr)
Mon, 18 Jan 1999 02:37:31 +0100


In article <Pine.SOL.3.95.990117185303.21500A-100000@albert.math.psu.edu> you write:
>
>
>On Mon, 18 Jan 1999, Marc Espie wrote:
>
>> >Sorry, but it means that standard C++ is fundamentally broken. *If* one
>> >has to avoid some features at any cost it means that you are advocating
>> >usage of language different from C++. It may be a subset of C++, but it is
>> >*not* C++ per se.
>>
>> Have you been using trigraphs recently ?
> They are outright silly and useless, but don't incur any overhead.
>Useless - yes, hurt anything except feelings of poor souls forced to read
>the code - no.
>> Do you feel forced to return structures in any program that you write ?
> Decent compiler (gcc, for example) handles it quite nice. Compile
>and look at the code. Oh, and wake up - you slept about 15 years.

Where have *you* been during the last ten years ? Can't you recognize
sarcasm when you see it ? Look, I was just trying to point out how silly
your point of view was... I think I've succeeded...

>> Do you feel obliged to use scanf and locales in any programs that you
>> write ?
> They belong to library. Standard library, but it means *nothing*.
>No, I don't count overloaded << and >> as elements of core C++. Elements
>of standard environment, yes. But *not* the language per se. BTW, I don't
>count STL as part of C++. (Reportedly) ugly library that got (reportedly)
>too popular, but that's it. Now, exceptions *are* part of language.

The STL is nowhere near as ugly as some parts of what makes linux tick.
The glibc for one. Or all the contorsions that you have to go thru to
define macros that work and don't invade the programmer namespace.

As far as exceptions go, what's your problem ? you don't necessarily
have to program with exceptions, as with C, you don't have to take locale
into account if you don't want to. What the compiler ends up doing as far
as performance goes, when exceptions are not used is a `quality of
implementation' issue, not definition of the language per-se. Last time
I looked, gcc allowed that you turn exceptions off for good.

>Templates are part of language. And they are *ugly*.

Ugly ? The C preprocessor was not nice & clean last time I looked, and
templates are definitely not ugly once you get used to them. Verbose, yes.
Ugly... well, such a statement probably means you have played with templates
ten minutes top. Or only read about them in the ARM.

>> Is C broken ?
> Everything is broken, but C is not even close to C++ in *that*
>kind of breakage.

You should try reading Stroustrup. Major design points of C++ have been:
- what you don't know won't hurt you,
- you don't have to pay for features you don't use,
- avoid gratuitous incompatibilities with what already exists,
- supporting several programming paradigms is nice.

This means that the C++ community makes no qualms about using
only parts of the language. This also means that parts of the language
could be simpler and nicer. For one thing, start by dropping backward
support for C. C has the same kind of problems: it took a while before
all compilers accepted struct passing, and C compilers still have to
deal with old-style K&R function declarations. Do you find the
equivalence: int f(x) float x; {...} == int f(double x);
to be very natural ? I don't. But it's there, because it's a real language.

Look, I'm getting out of this flamewar. This is getting plain silly.

Again, my position is pretty simple: I do agree that nobody is going to
rewrite the kernel in C++ anytime soon, because there are very large
cultural reasons against that. It's much easier to write very powerful
code in C++ than in C... guess why the C++ io-library can go faster than
the C io-library, when implemented correctly. It's also much easier to write
atrocious code in C++, ESPECIALLY if you don't know the language well, and
if you use every goddam feature the language offers. C++ extends C to
cater to the needs of several distinct communities, and it can excell in
most areas. It's also several times larger than C, and takes much more time
to master.

But there is no technical reason why this should be so. Most of the arguments
against C++ on this list have been highly opiniated, and somewhat
uninformed... `C++ bashing', you could say. I'd hazard they come from
people who worked in C++ on brain-dead compilers, on older g++, or with
colleagues with a highly-twisted sense of what constitutes nice code.

Templates ugly ? The STL `reportedly' ugly library ? Give me a break...

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/