This Space for Rent

C++ considered harmful

By itself, it's not that bad. It's not C, and its developers keep trying to reposition it ("inheritance is good" "No, inheritance is bad! Templates are good!" "No, no, Templates are bad! Patterns(tm) are good!") to sustain some sort of dominance in the damned vanity language of the century competition (a doomed battle; monstrosities like p*th*n and p*rl [and all the little nichey languages that float around the periphery, all barking for their 15 minutes of fame] are much better suited for the damned vanity language crown because they're interpreted languages, and interpreted languages are, by design, much better suited for making your brain explode 47 different ways before teatime), but if you realize it (C++, that is) it's C with an attached unstable nuclear device and code accordingly, you can do wonderful things with it.

What's really wrong with C++ is that the C++ fanatics have crept their way into the standards commmittees for C (which may not be the One True Language, but it's a lot closer than C++ is), and thus C++ "features" have found their way into "revisions" of the C language. Like, oh, // to start a comment.

I'm aware that every long-lasting language has been subjected to the tender mercies of the standards revisors. I used to program occasionally in FORTRAN, and I know I'd have to rewrite that code from scratch if I had even the slightest hope of making it compile with a modern FORTRAN compiler. But it still annoys me to death when I try to build someone else's C code and gcc 2.7.3 (which, last time I checked, a legitimate C compiler even if it's surrounded by wads of GNU crapware extensions) and I have to go in and convert a bunch of // comments into / ... / ones.

ClamAV bit me on this one today; I had to upgrade the version of clamscan on pell from 0.65 to 0.84rc1, and (alongsize the usual crop of things failing because Pell is not running R*dh*t 8.0) a few // comments popped up and caused gcc to become very unhappy with me.

Not as unhappy as the Linux kernel would make it, of course (the Linux kernel isn't actually written in C, it's written in whatever version of gcc is shipped with the distributions that the core team uses, and since gcc has embraced C++ extensions for a long time the code is infested with // comments) and nowhere nearly as unhappy as McAfee's antivirus code used to be (McAfee used to develop their antivirus on W*nd*ws, and every compiler there treats C and C++ as one and the same. Thus about 75000 // comments in their scanner engine), but it's still annoying, and a good reason to start grumbling about "dictator of the world" and "first up against the wall when the revolution comes".

Comments


// style comments were in C's ancestor BCPL. They are also part of ISO C99.

Anon Fri May 27 23:38:34 2005

ISO C99 is not C; C, as K&R developed it, doesn't use g-dd-mn // as a comment marker. BCPL may use // as a comment marker, but it's not C either.

I get somewhat anal about this because I like to pretend that C code is actually C code; code that's written to K&R 1 and K&R 2 is (or used to be) portable to pretty much every machine that ever had a C compiler ported to it. The new "C" code, well, that code won't compile on anything except the exact version of GCC that it was first compiled on (and many of those versions of GCC won't compile traditional C code that uses any of the K&R 2 ANSI preprocessor extensions.)

David Parsons Thu Jun 16 11:46:01 2005

Comments are closed