Some thoughts on C

I’ve recently started learning C after spending a good few months with Python. C is certainly a whole new ball game, there are some things that I love and some things that I’d rather do without. Here’s a quick rundown of some of the things that have made an impression on me:

  1. C feels more formal. Every programming language has a distinct ‘feel’ which you start to understand once you’ve used a fair number of them. Perl feels snappy and lightweight. Python feels quick and flexible, but there’s also this feeling of underlying power. Java feels heavy, rigid and structured, sort of like the Empire State Building. Scheme has this very mystical, arcane, almost magical feel to it. C feels formal and structured like Java, but less heavy. It certainly feels more formal than Python and compared to Scheme, actually feels kinda boring, but that may just be me.
  2. C requires more patience. Since C is purely compiled, it means that you have to wait around for everything to compile before you can get to fixing errors and this can take a lot of time if your program stretches over more than a few hundred lines. The wait is even longer if you’re running after logical errors that only show up at runtime. The multiple edit-compile-run cycles can become very frustrating, especially if you’re used to the zippiness of interpreted languages.
  3. With great power comes great responsibility. For people like me who’s first encounter with programming didn’t involve manual memory management, C opens up a realm of possibilities thanks to it’s pointers which make it very easy to directly access system memory. While direct access to memory lets you write a lot of fast, powerful code, it also brings with the worst of every systems programmers’ nightmares: memory leaks, buffer overruns, accidentally wiping parts of the memory you weren’t even supposed to know existed, the list goes on. While languages like Python, Perl and even Java would happily clean up after, there’s nothing like that in C (unless you want to write your own garbage collection routines, but that’s a whole new ball game). Programming in C certainly makes you a more careful coder.
  4. You learn more than just programming. A lot of code is written in C, including a lot of very high quality open source code. If you decide to really learn C and use it for large scale projects, you probably won’t be able to avoid learning about Makefiles, version controls, the intricacies and optimizations offered by the various C compilers, and of course a rather frugal attitude towards memory management.
  5. The text editor is your best friend. There are lots of C IDEs out there, though many of them are very good, there’s no actual standard or default and in most of the ones you try, you’ll probably find a feature or two that you want but don’t have. Though I like IDE’s myself (DrScheme for Scheme, Eric3 for Python, BlueJ for Java), I’ve decided to stick with Vim, a really nice C plugin and the command line for my C programming. Many open source programmers find this sort of setup the best deal, especially if you start using makefiles. This probably isn’t C specific, because ideally you can use this system for most languages, but C sort of rubs it in.

That’s all for today. Next we take a look at using the Vim editor for C programming.