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

Curiosity: Perl File Extension in Emacs Config

A curiosity question.

emacs's “auto-mode-alist” has this value:

("\\.\\([pP]\\([Llm]\\|erl\\|od\\)\\|al\\)\\'" . perl-mode)

the regex there seems a bit wild. If i didn't get it wrong, then its like this

. ([pP] ( [Llm] | erl | od ) | al )

so it covers:


plus SOME case variations. e.g. {.pL , .PL}.

what's the “.al” for?

is it necessary to include the “.pod”? because the perl-mode doesn't do any coloring with “.pod” files, nor cperl-mode. If there's a mode handing “.pod” file am guessing it won't be perl-mode.

also, is the “.perl” there necessary? Is that a accepted perl file suffix? (Just checked it's not in any file bundled with perl v5.10.1.)

would it be better if it's just

("\\.\\(p\\([lm]\\)\\)\\'" . perl-mode)


Tonight I'm Frakking You

Perm URL with updates: http://xahlee.org/funny/tonight_im_frakking_you.html

Tonight I'm Frakking You


emacs lisp: getting current buffer path

In your elisp program, you may call (buffer-file-name) to get the full path of the file, but sometimes the current buffer isn't associated with a file, so your program will fail.

Here's a idiom: (or (buffer-file-name) default-directory). This way, if the buffer isn't a file, it'll return the directory path of the buffer. (when a buffer is created, its “default-directory” is typically the same as previous buffer. In the case of temp buffers created by emacs such as {*info*, *scratch*, *Bookmark List*, …}, it's usually home dir.)

I just searched all my elisp files for this oversight.

BMW's Sexual Ad

post removed because it might violate Google's ad program policy. See here instead: 〈Xah's Sex Blog〉 http://xahlee.org/sex/blog.html

Gauss's construction of the 17-gon

Gauss's construction of the 17-gon (Heptadecagon). He probably didn't actually draw it, only proved possible.

Gauss construction 17-gon
Gauss construction 17-gon (unverified)

More info on Wikipedia Constructible polygon


Emacs Lisp: Ways to Exit/Break a Loop

Perm URL with updates: http://ergoemacs.org/emacs/elisp_break_loop.html

In many languages, there's “break” or “exit” keywords that you can use to exit a loop. In functional programing, usually you don't do loops or exit loops, but sometimes that's just what you need.

In elisp, to exit loop, you can either use a flag (i.e. set a variable to indicate whether to exit.), or use the built-in catch and throw.

Using a Flag

Here's a pseudo-code for using a flag:

(while (and (not found) (< i listLength))
 ; if found, set found

 (setq i (1+ i))

Here's a actual example using a flag:

(defun get-new-fpath (ξfPath moveFromToList)
  "Return a new file full path for ξfPath.
moveFromToList is a alist."
  (let ((ξfoundResult nil) (ξi 0) (ξlen (length moveFromToList)) )
    ;; compare to each moved dir.
    (while (and (not ξfoundResult) (< ξi ξlen))
      (when (string-match (concat "\\`" (regexp-quote (car (elt moveFromToList ξi))) ) ξfPath )
        (let (
              (fromDir (car (elt moveFromToList ξi)))
              (toDir (cdr (elt moveFromToList ξi)))
          (setq ξfoundResult (concat toDir (substract-path ξfPath fromDir)) )
      (setq ξi (1+ ξi) )
    (if ξfoundResult ξfoundResult ξfPath )

Using throw and catch

Here's a pseudo-code of throw and catch.

(catch TAG
   (lambda (x)
     (if …
       (progn (throw TAG VALUE) )
       (progn …)
 ‹value of catch if throw didn't occur›

Here's a example using throw and catch.

(defun xahsite-url-is-xah-website-p (myURL)
  "Returns t if MYURL contains a xah domain name, else nil.

See: `xahsite-domain-names'."
  (catch 'myloop
    (mapc (lambda (x)
            (when (string-match-p (format "\\`http://\\(www\\.\\)*%s\.*/*" (regexp-quote x)) myURL)
              (throw 'myloop t)))

(info "(elisp) Catch and Throw")

JavaScript: Exclamation Before function

I come across JavaScript code like this today:


What does that !function mean?

Turns out, it is equivalent to this:


The exclamation makes the function a expression. (it's the boolean “not” operator.) People do this hack to save one character worth of source code file size. Silly.


List of Keyboards with Mechanical Switch

Perm URL with updates: http://xahlee.info/kbd/keyboards_with_mechanical_switch.html

Here's a quick list of keyboards with mechanical switches. They typically start at $70. Ergonomic ones with fancy shapes usually starts at $200. (If you don't know what Cherry MX means, first see: Guide to Computer Keyboard Key Switch Mechanisms.)

Note: Microsoft or Logitech keyboards do not use mechanical switches, even expensive ones.


Truly Ergonomic Keyboard (Cherry MX Brown)

The μTRON Keyboard (hard to buy in USA)

Kinesis Contoured Keyboard (Cherry MX Brown)

Maltron Keyboard

Datadesk Tech Smartboard Keyboard. (may be hard to buy) Picture at Ergonomic Keyboards Gallery


Corsair K60, K90 (Cherry MX Red)

Filco Majestouch. Produces many different models, with or without numberical keypad, and also with many switch type: Brown, Black, Blue, or Red. Be sure to read model's spec in detail. (104 keys: amazon) (See: Keyboards Without Numberic Keypad.)

Razer BlackWidow. (Cherry MX Blue) amazon

Cooler Master keyboard. (See: Keyboards Without Numberic Keypad.)

Azio Levetron Mech4 Gaming Keyboard. (See: Keyboards Without Numberic Keypad.)

Das keyboard. Some model are not mechanical. Be sure to check spec. (➲ review here)

Ducky keyboard (may be hard to buy in USA) (➲ KBC Poker Keyboard, Ducky Keyboard)

KBC Poker keyboard (may be hard to buy in USA) (➲ KBC Poker Keyboard, Ducky Keyboard)

Unicomp IBM Model M (➲ review here)

Happy Hacking Keyboard (professional model only) (➲ The Idiocy of the Happy Hacking Keyboard)

SteelSeries 6Gv2 keyboard. (Cherry MX Black) amazon

Matias Tactile Pro 3.0. Switch Type: White Alps Strongman. http://matias.ca/tactilepro3/index.php

• Adesso Full Size Mechanical Gaming Keyboard with USB Hub and Audio Jack - USB and PS/2 (MKB-135B) Adesso MKB-135B Pro. Switch Type: Cherry MX Blue. amazon

Cherry SmartBoard G83-6744 Keyboard - wired - Black - English - US http://www.cherrycorp.com/english/keyboards/Office/G80_3000_MX/index.htm amazon


Wordy English: A Etymology Rhapsody on Spiracle

New Wordy English article: 〈A Etymology Rhapsody on Spiracle〉: spiracle, fan, allophone, camouflage @ http://wordy-english.blogspot.com/2012/07/etymology-rhapsody-on-spiracle.html.

Be sure to subscribe Wordy English for literature/writing/vocabulary related articles.

Emacs: Ways to Jump to Points

when coding, there's a common need to jump to a particular place, then return to previous position.

There are several ways. Most common standard way are:

  • exchange-point-and-markCtrl+x Ctrl+x】.
  • Ctrl+u Ctrl+Space

I've tried all ways in past years, including custom elisp that push marks. But i found split windows to be the best.

e.g. split window. Go to where you wanna be. When done, unsplit. Give split/unsplit a easy key. (➲ Emacs: How to Define Keyboard Shortcuts) e.g. In ErgoEmacs, it's:

  • Alt+3delete-other-windows
  • Alt+4split-window-vertically
  • Alt+0delete-window
  • Alt+sother-window

On a different note, here's a nice tip when using mouse (thx to Ken Goldman):

  • Middle mouse button on a status bar expands current pane.
  • Right mouse button on a status bar closes current pane.