jvdb.org Blog

C is (still) everywhere

on Wednesday 16 February 2005 @ 13:08 in Software Construction

Jon Galloway posted that he disagrees with one of the points in Joel Spolsky’s Career Advice column, specifically this one: Learn C before graduating. Jon goes on to provide six arguments why you shouldn’t learn C anymore if you’re not familiar with it now and you want to get into software development. I disagree with most of his points, but the most important one (and therefor the one I’ll respond to) is this one:

Quote from Joel’s article:


I don’t care how much you know about continuations and closures and exception handling: if you can’t explain why while (*s++ = *t++); copies a string, or if that isn’t the most natural thing in the world to you, well, you’re programming based on superstition, as far as I’m concerned: a medical doctor who doesn’t know basic anatomy, passing out prescriptions based on what the pharma sales babe said would work.

That sounds good on the surface, but does his code sample really tell you how the string is being copied? It’s a symbolic representation of a process which is moving memory, sure, but still several levels of abstraction away from shuttling the bits through memory. Why is this the magic level of abstraction that gives you the edge? Why not assembler?

Worse still is that it can make you think that programming is about telling the computer what to do with its registers and memory. Oops, wait, that memory was magically paged from disk without your knowlege. The compiler applied some optimizations behind your back. Your code is running on top of an operating system, which is�rationing out the CPU cycles between tens of processes, and yours gets a measly 10% timeslice. And, hey, what CPU are you on? Any sneaky little tricks going on with your 64 bit hyperthreaded chip? What about two years from now, when you run your app on a virtual server on a multicore chip?

Thinking that you’re in the pilot’s seat because you’re handling pointers is silly. Better to understand that you’re asking the CPU(s), through multiple levels of abstraction, to copy a string. Do it politely – this ain’t no rowboat anymore, it’s a durned space ship.

However, All popular spaceships (and a bunch more) for now and the forseeable future are written in C. So while it’s absolutely true that the level of abstraction that C teaches you is far from all possible angles you can have with regards to what happens with the software you write, it’s currently the one that undoubtedly matters most. Whenever you find a weird quirk in functionality exposed by an API, be it a .NET Framework class library, a Java package, an STL template or an opensource GUI toolkit, chances are that it will be related to the original implementation of that functionality in the operating system. And all of them are written in C. So what’s a good language to learn before you graduate?

Leave a Reply