RE: Stop Hating on C!

This started off as just a comment to an interesting, but slightly perplexing post, but since it got a bit long, I thought I’d make a full post reply.

This isn’t applicable to you specifically, but since you brought it up, I thought I’d clear up a few misconceptions about us “haters”.

You’re reading too much into it.

I haven’t come across anyone who really hates C or anyone who would claim C isn’t a language worth learning. In fact, if OSes and bootloaders are being discussed it’s usually the first language to be mentioned after Assembly.

When we had no other intermediary, Assembly was the language of choice for writing an entire OS, but then C came along and that was used at a higher level. Back then you still needed direct hardware access due to a lack of some “middle layer” in terms of software so programmers of the day wrote everything in it. This changed as other higher level languages came along freeing developers to do more complex tasks with fewer libraries and with greater efficiency.

The biggest problems with C are its advocates.

I would argue the same holds true of Assembly. It’s a fine language for what it does and is appropriate for. But writing entire OS in it is a bit silly from a practical viewpoint aside from an interesting technical exercise. Or bragging rights; whatever floats your boat.

However I’ve yet to have an Assembly programmer push its use on me for everything. Now that may also have something to do with the fact that I could count on one hand the number of people I’ve met who have programmed in Assembly.

“C isn’t badly designed or overly complex” and I whole heartedly agree, when it’s being used appropriately. But when a hammer is used in ridiculously inappropriate ways, we don’t hate the hammer, just the guy who used it on a screw. There’s a place to use it and claiming it’s the greatest thing since sliced bread for religious reasons is unhelpful (note in that article, he states “Why C++ is a superior general purpose programming language”).

The language is fine for what it does, but when we see it being used on things where other languages with greater capabilities and ease of use in high level tasks are more fitting, yeah, it grates a bit. Headers are appropriate when the complexity of the job at hand requires a sane degree of them unless another language like, say, Python or Java or C++ gets the same job done in less time, with the fewest number (if any) of third-party libraries.

There’s a header to native support ratio in any project and once that exceeds acceptable levels, it’s time to move on.

The basics

Once you understand pointers, memory allocation and integer arithmetic, you will have a basic, intuitive understanding of the beast that makes your computer tick, and no programming language will ever scare you again.

These things should be (and are) the first things taught to any would-be programmer. Learning the core functions of a CPU is fine indeed, and I encourage any enterprising student to learn it thoroughly before moving on. Use that knowledge to better leverage the high level capabilities of another language when that’s being used, after all, every language gets reduced to machine code in the end.

No one (who isn’t a complete nutjob) is advocating we completely abandon C or stop teaching it in school altogether. We’re just tired of programmers who shoehorn it in places other languages do better.

What does “do better” mean?

I’m not just talking about code efficiency or low-level reach. Human efficiency is often more important than code efficiency.

We often take this for granted when we forget we’re human beings prone to failure (personal and professional), subject to absent-mindedness, to caffeine deprivation, to sleep deprivation, to mood changes, to divorce, to bankruptcy, to illness, to accidents and even death. In this sea of fallibility a ship that requires constant attentiveness and fine tuning — while it may allow you to know the inner workings of the ship better than any other person the world — is also prone to let you down in a storm should our nature kick in at the most inopportune time.

So I have to consider: Should I choose a language or programming environment in the comfort zone? Or one that allows me to sail safely, sanely, efficiently and, should I one day be incapable of handling this ship (and that day will come whether I welcome it or not), be easy to teach (less complex) to a new generation and would that new generation accept it and use it wisely? I’ll still make sure the new generation knows how the engines work with intimate detail, but I’m more likely to choose the latter.

Try not to think that others are hating on C. Ask yourself whether you love it for the right reasons.

Update 04/17

I came across this video by Larry Wall, creator of Perl makes some interesting points on the idea that some languages get promoted for reasons other than their technical merit (segment starts at 3:45).