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

9 thoughts on “RE: Stop Hating on C!

  1. This reminds me of similar discussions I’ve had with some folks who’ve argued that PHP should be the sole language of anything web-related. Not JSP, not .NET, not Ruby, but PHP, regardless of the project. It’s that final point that’s crucial, and indicates a religious devotion to the language as opposed to recognition of the language’s strengths and weaknesses.

    It’s also the point where I stop taking the person seriously and switch to trolling mode :P

  2. On a more relevant note, I love C. I think it’s an absolutely phenomenal language that everybody should learn and use at some point. I also think using it to write something like a mail client or instant messenger is incredibly silly when you have languages like Java or even Python available. You put it perfectly: find the right tool for the job and use it accordingly. Just because you’ve learned how to use the C-hammer doesn’t mean everything is a C-nail.

  3. Nice to see a response to my post. You raise some good points.

    I should probably add, though, that I come from the academic world (computer science). I’m sure people in the industry have more appreciation for C, since it’s still widely used. In the academic world, however, people will often completely dismiss the language for the various reasons I mentioned. These people don’t realize that writing an operating system kernel or game engine in Haskell or Scheme would be rather problematic, for a multitude of reasons.

    • Ah! Now that does bring more clarity to the picture.

      I would say then, those people in the academic world who dismiss it offhand haven’t really had to solve problems that could make or break their careers. They’ve never been used to solving properly practical problems on a 1-to-1 scale with a deadline where ideological purity over practicality is a death sentence.

      My only suggestion when dealing with these people is to invite them to write a kernel or game in Haskell or Scheme. Hopefully they’ll come to understand the limits of the language before they lose their enthusiasm for it.

      Often, you’ll see singers, songwriters and musicians leave the recording industry altogether before they start to hate what they’ve always loved to do. I’m hoping similar exposure would be enlightening in the programming world.

  4. This is a great post! I think you are absolutely right that you have to pick the right tool for the job. For example, Python is an easy to use, easy to add to (modules), and pretty looking language. Python is very hard to work with when trying to make a GUI though.

    • Thanks! Yes, that’s exactly what I mean.

      I would say that if I had to choose between Python and PHP for web development I’ll definitely choose Python. It’s not perfect by any means, but it’s one of those languages that “do better” at what it does. ;)

  5. Absolutely one should pick the best tool for the job. I would however argue that if you don’t know C then you aren’t well informed enough to pick the right tool. I consider it vital that all programmers know exactly how their hardware is working, and no language does that better than C. Anybody who wishes to be a master programmer should know how their favourite high-level language features can be roughly expressed in C code.

    I’m not advocating programming in C, just that you know how it works. I find that people without this knowledge have great difficulty in doing optimization, and have difficulties finding performance bottlenecks in their code. They also don’t understand how fast the system could be and are simply reliant on how fast their program is.

    • Very true.

      It’s like going to the mechanic. You’re less likely to get ripped off if you know how your car works. Maybe even save a bit by fixing it yourself.

      And, if you get bored of what you’re using now, it helps to know it just so you can create your own language with a layer of C beneath. Plenty of people have created their own this way and it creates a new fertile ground for innovation.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s