Why I Hate C

Perm URL with updates: http://xahlee.info/comp/why_i_hate_C_lang.html

I despise C the language, not because of particular technical aspect, or lacking some functionality such as lacking {automatical memory management, module system, namespace, list/hashtable datatype, complex number datatype, regex, function closure, function as value, OOP support, functional programing support, …}, none of that, but on certain sloppiness that's in the bones of C. (pretty much like unix (they bootstrap each other (it's scam booting scam)))

Perhaps the best simple example to illustrate, is its invention of the format function printf. Completely ad hoc, inflexible, cryptic syntax and semantics. When i first learned it (thru Perl. (C/Unix has a knack like virus. Now it's in about every lang.)), i went WTF is this? (i came from Mathematica). The printf can print hex, but with fixed representation of the digits, and can't do arbitrary n-based number system. It can print decimal in several formats, but in a bunch of ad hoc fixed ways. And did i mention cryptic syntax? The syntax and semantics isn't extensible in any general way.

There it is, the C language! In C, just about anything it does, it's done in a {ad hoc, fixed, inflexible, non-extensible, cryptic} way, and with a PRETENSE that it is done for speed and efficiency. Note the word “PRETENSE” here. That's important. I don't dislike C because it's a low-level, system language, designed for speed, but because there's a strong HACK element in its blood.

(to this day, due to C's spread of printf, many programers don't really understand what's n-based number system, they just recognize {binary, oct, hex} when they see a string of 0123456789abcdef. And if you show them hex number system using decimal digits in a list, they would be wildly flabbergasted and goes “WHY would you ever want do that??”. To this day, the hex with 0…9a…f have so ingrained in every computing spec. In particular, RGB color e.g. #c2c2c2. (the RGB color spec, is a entire story of complete ad hoc f��� by itself (e.g. ad hoc range of 0 to 255, just because it is convenient at the time!). (not sure who started it, probably unix X11 first popularized it.)))

• Extensive ad hoc syntax. So, we need to increment a counter often. Instead of working on a better compiler, let's invent a short syntax on the spot! Thus was born these abomination: {i++, ++i, i--, --i, =+, …}. And witness the syntax soup: {i++, ++i, for(;;){}, while(){}, 0x123, expr1 ? expr2 : expr3, sprint(…%s…,…), …}. These are ad hoc, cryptic, inflexible, non-extensible, syntaxes — the nature of C. (➲ The Concepts and Confusions of Prefix, Infix, Postfix and Fully Nested Notations)

• the use of bitmask as boolean parameters. (to this day, there are programers who don't understand the difference between a set of true/false formal parameters vs their internal representation, and insists that bitmask is the most efficient way to “encode” boolean parameters. Encode? Encode their ass. (this again, spread like virus. You see it in perl/python regex flags. Did i mention cryptic?)) (➲ Programing Language Design: the Hack of Bitmask Used as Boolean Parameters)

• the include as a lib system. No namespace. Granted, in the 1970s, computing resources are meager. Many of C's issues we can't really blame C. But, the key point i want to emphasize is, that everything in C is done is a sloppy no-design way without any apology. If pressed, the C types delight in the ad hoc cryptic nature as hackery. It “give them freedom”, it “allow them to shoot their own foot”, it “is for real programers”, …, they chant. (much inherited by Perl) So, C's include has gone into Perl, and from Perl to PHP. (luckly, include fell off starting with Perl in the late 1990s. Most langs now have a namespace/module system.)

• cryptic error code. This have been transfused into the veins of unix. You have to check the exit code, then you need to decode the error code. And here we onto the related bitmask f��� as in unix.

C and unix are such a sloppy, spineless tech that they act like a virus. (this point has been well exposited by lisper Richard P Gabriel's 〈The Rise of “Worse is Better”〉.) C spawned csh, C++, Perl, Java, Pretty Home Page (aka PHP) (and the entire C-like syntax langs), C#, Go Lang. They ride on sloppiness and speed which masquerade as portability and distributed like drugs. The whole C Unix things spread like drugs, in particular: unix, perl, Apache, MySQL. Their slogan is often “MOST Popular in Industry!”. And as a consequence, usually “Industry STANDARD”! O, and there is one thing that always accompany these: $FREE$! (as in, free drugs!)

So, C++ is better? if you think C++ fixed C, then this whole essay has been written in vain. C++ is far worse. (in the context of this essay, Java can be considered as a improvement of C.)

Popular posts from this blog

Browser User Agent Strings 2012

11 Years of Writing About Emacs

does md5 creates more randomness?