Log in

No account? Create an account
Adventures in Engineering
The wanderings of a modern ronin.

Ben Cantrick
  Date: 2008-08-23 12:46
  Subject:   Quit damning C with your faint praise.
  Mood:Get off my lawn, damn kids!
  Music:KMFDM - Power
  Tags:  reddit

Here’s the thing: C is everywhere. Recently Tim Bray made basically the same point; all the major operating systems, all the high-level language runtimes, all the databases, and all major productivity applications are written in C. And there are many other categories of software that I haven’t even mentioned, all written in C.

So can you as a developer choose to ignore it? Live in high-level language land for your entire career? I would say almost certainly not. High-level languages often provide abstractions that relieve you from the burden of dealing with the platform on which you’re building. Which is great, but sooner or later a crack is going to open up and the abstraction is going to leak.

Some day you’ll need to go spelunking into the depths of your runtime environment. Maybe you’ll need to call some other C-based API for which you don’t have a convenient wrapper in your high-level language of choice. Like, say, mmap-ing a part of a file instead of the whole thing. Or maybe you’ll just want a bit of a performance boost. And on that day, boy will you wish you knew C.

It’s for this pragmatic and entirely non-bigoted reason that I promoted C to the top of my language pantheon. If you’ve never learned C, it means you’ll never be able to delve too deeply into the foundations your programming environment and find out exactly what is happening under the surface, or to extend it in any way.


Do these arguments ("it underlies everything", "you need it for maximum performance", "it's the only way to do certain things") sound familiar at all?

How about if you s/C/assembler/g and read again?

C will go the way of assembly sooner or later. All the same arguments are being made in its defense. The only question is, how long will it take? Don't get me wrong - I like C, and I hope it will be a long, long time before it goes away. But don't kid yourself. Nobody learns assembly any more (except for embedded engineers and a few EEs), and there will come a day when C suffers the same fate.

And frankly, I find all this over-blown defense of C to be stupid. Quit damning C with faint praise. It is a perfectly good programming language on its own merits. So good, in fact, that it's spawned a horde of imitators and knock-offs. C++, Java, C#, etc, etc - they're all based on C syntax. Partly a historical accident? Sure. But ask yourself this: if it's only about history, why didn't FORTRAN or COBOL come to dominate? You pretty much have to concede that C is awfully good for a language invented 35 years ago.

If you really want to defend C, how about less of this "well, you have to know it, because everyone else knows it!" argument-from-popularity bullshit1, and a little more of the "C is a good language because..." A) it's relatively simple and clean, B) anything you want to do, someone HAS done it before in C, and you can probably download the code, and C) yeah, okay, when performance does matter2, C is a reasonable choice.

N.B. Pre-emptive stike against the C++ weenies: NONE of the above arguments are meant, in any way, to defend or endorse C++. I am talking about, at most, C99 here.

1 Save that for your vi vs emacs holy wars. Lamer.
2 Which it very often does not - see Programming As If Performance Matters.
Post A Comment | 3 Comments | | Flag | Link

Alex Belits: iskra
  User: abelits
  Date: 2008-08-24 04:13 (UTC)
  Subject:   (no subject)
I disagree.

First of all, C replaced assembler only after covering all functionality of assembler. And by all I mean all -- currently I write code with CPU-specific instructions wrapped as C macros, and they compile into the same kind of code I would write in assembly directly. A program in C differs from a program in assembly only by resources being "anonymized", leaving register and memory layout optimization to the compiler. Considering that there is plenty of resource optimization that happens on hardware level (cache, pipelines), it is reasonable to leave general-purpose register allocation to compiler. And whenever this is insufficient, inline assembly in C keeps C language features such as access to variables.

The idea of all modern languages that are not C is to provide higher levels of abstraction while removing access to the lower ones. C is unique not because it uses currently lowest level of abstraction programmers are comfortable dealing with -- it is unique because it goes below that "comfortable" level. I don't see anyone even suggesting a possible development of a comparable language.

Second, actually in engineering of all kinds argument from popularity implies "it's popular because it's good", what often is the case. Software development is a very unusual area -- it is chock-full of massive engineering failures being widely adopted due to ideas being too close to products. By successfully marketing a poorly designed OS-level, infrastructure or developer-oriented product one automatically promotes ideas and the whole worldview that has to be adopted to use that product efficiently, thus automatically recruiting supporters.

This is why I see Windows-only programmers as people whose ability to develop software was damaged and subverted into perpetuation of stupid ideas placed into Windows design -- it's not as much a problem that they write a lot of potentially popular software that promotes USE OF WINDOWS, as that they both promote and demand Windows-like brokenness of software made by others, so everyone WRITES EVERYTHING AS IF IT IS FOR WINDOWS.

"Forced popularity" looked like a valid accusation toward C when it mostly followed use and development of Unix, however it became clearly invalid when C thrived where/when Unix was unpopular -- desktop PC and embedded software in 80's-90's. What we see now in rising popularity of Linux and BSD in embedded systems is this process going into the opposite direction -- popular language "supporting" the environment where it was originally developed, once that environment became usable for a wider range of applications that language already covered.

And I hope, no one is going to accuse modern Unix-like OS of being popular in embedded systems ONLY because they are written in C. They were completely defeated in mid-80's in all parts of maket/mindshare other than servers, and made a comeback because of their superior design and increased requirement for OS in embedded systems. C merely allowed embedded systems developers to migrate there while continuing using the same language.
Reply | Thread | Link

  User: ext_119615
  Date: 2008-08-28 03:33 (UTC)
  Subject:   (no subject)
s/C/assembler/g and it becomes plainly wrong. So, all major databases are written in assembler are they? Which ones would these be, then?

Also, I am not appealing to popularity. I'm not saying you have to know C because everyone else knows it. I'm saying you should know C because it is the language in which so much essential software is written. It's an argument not based on anyone else's opinion, hence cannot be an appeal to popularity. Every developer in the world could drop dead, and my argument would still hold.

On the subject of logical fallacies, your argument sounds like an instance of the package-deal fallacy. Because assembler suffered some fate, so too will C because people say the same sorts of things about it? I don't believe you.
Reply | Thread | Link

Ben Cantrick
  User: mackys
  Date: 2009-09-06 20:36 (UTC)
  Subject:   (no subject)
> I don't believe you.

Luckily, history will prove or disprove our respective points of view.

The annoying part is, we have to wait...
Reply | Parent | Thread | Link

May 2015