Why I Hate the C Language

By Xah Lee. Date: . Last updated: .

Why I Hate C (The Greedy Design Paradigm)

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, etc}, none of that, but on certain sloppiness that's in the bones of C. (pretty much like unix (they bootstrap each other (it's virus booting virus)))

Printf syntactic wart

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 hexadecimal 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 hexadecimal with 0…9a…f have so ingrained in every computing spec. In particular, RGB color, for example: #c2c2c2. (the RGB color spec, is a entire story of complete ad hoc faak by itself (For example, 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, =+, etc}. And witness the syntax soup: {i++, ++i, for(;;){}, while(){}, 0x123, expr1 ? expr2 : expr3, sprint(…%s…,…), etc}. These are ad hoc, cryptic, inflexible, non-extensible, syntaxes — the nature of C. 〔see Concepts and Confusions of Prefix, Infix, Postfix and Lisp Notations

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 ya ass. (this again, spread like virus. You see it in perl/python regex flags. Did i mention cryptic?)) 〔see Hack of Bitmask as Boolean Parameters

The “include” slurp

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 faak as in unix.

Worse is Better

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). 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.)

Great Syntax Design for Number Literal

A literal number syntax design that incorporate any base up to 36, and scientific notation, and optionally embed info about precision or accuracy. Opposite of the unix c hacks.

WolframLang number syntax cSNK
WolframLang number syntax

In sharp contrast to C lang's design for number literals, which is ad hoc and puny and incomprehensible.

C. A. R. Hoare on C

  • C. A. R. Hoare in an introduction to the classic paper, An Axiomatic Definition of the Programming Language Pascal , for the book, 〔Great Papers in Computer Science By Phillip Laplante. At https://www.amazon.com/Papers-Computer-Science-Phillip-Laplante/dp/0780311124〕.
  • In reference to his goal of designing a better programming language - one which makes it easier to write correct programs and harder to write incorrect ones - Hoare writes, “It is a matter of continuing regret that so few languages have ever been designed to meet that goal, or even to make significant concessions towards it.
  • For example, the programming language C was designed to assist in writing a small single-user operating system (UNIX) for a real-time minicomputer (PDP 11), now thankfully obsolete.
  • For this purpose, its low level of abstraction and plethora of machine-oriented features are entirely appropriate.
  • For all other purposes, they are a nuisance.
  • The successful propagation of the language can be explained by accidental, commercial, historical, and political factors; it is hardly due to any inherent quality as a tool for the reliable creation of sophisticated programs.”

[2020-06-09 from http://pascal-central.com/ppl/chapter4.html]

Crime of C Lang, Constants as Macro

why c sucks 2024 HPXCd
why c sucks 2024 HPXCd
why c sucks 2024-01-03 001515
why c sucks 2024-01-03 001515
why c sucks 2024-01-03 001522
why c sucks 2024-01-03 001522

Python C C++ goto Jail

python C Cpp goto jail  Francois Rene Rideau lisper on C
https://plus.google.com/+Fran%C3%A7oisRen%C3%A9Rideau/posts/Le5VCYpvuuQ

A Guide to Undefined Behavior in C and C++, Part 1 By John Regehr. At https://blog.regehr.org/archives/213, accessed on 2015-08-16〕

Most Vexing Parse

most vexing parse 2019-09-11 xnngm
https://en.wikipedia.org/wiki/Most_vexing_parse

Xah Talk Show Why I Hate C

vidthumb c9gpHHUaozU

worse is better

Programing Language Love and Hate