Friday, September 18, 2009

Standing on the Shoulders of Giants, or Why I Learned to Love the C

One item in my list of "Things I Do Not Understand" is people who tout the performance of an application that uses an interpreted language. Seriously, folks, if you're using Python, Ruby, or Erlang, you're not building it for raw performance. You're doing it because the language is giving you convenient features that make your life easier.

I'm not crapping on interpreted or otherwise "slow" languages. I'd bet there are many apps that flat out wouldn't exist if it weren't for the rich feature sets interesting programming languages provide. For example, while I'll argue that all apps could be re-written to scream using assembly language, I'll also argue most apps wouldn't exist if assembly was the only option. I mean, really, would we have icanhascheezburger if the guys had to code the whole thing from scratch using "mov eax, 4" and "add ebx, [ecx]"? No.

Like all things, there is a trade off between convenience and performance. This is why race cars don't typically have air conditioning and power locks. I have spent the last 10 years programming in languages that are like a heavy, comfortable Lexus. It has been nice. My apps are gratifying, easy to use, simple to understand. Are they fast? meh... They get the job done.

Recently, I have been thinking about writing distributed apps. I want to get good at writing multi-threaded monsters that take full advantage of multi-core architectures and can be distributed across many machines. I had a look at erlang. Looks awesome with all those features that help you distribute your workload across all the machines in the room. Then I had a look at the benchmarks. meh... Erlang really isn't that fast.

That was the day I decided to look at some other benchmarks to get a feel for what they really mean. A friend pointed me to this:

http://shootout.alioth.debian.org/u32q/benchmark.php

Wha?? At that time I was trying to build this super high performance thing using stackless python. I loved the microthreads, the convenient syntax. I loved how I could quickly go from a blank screen to running code.

I was shocked to see it was 63x's slower than C. I wanted to build a stripped down Porsche track car, not a fat Infinity.

The hole got deeper when I started thinking about what kind of code I wish I could write. I started digging through source code of the apps I look up to, you know the apps that are out there that get the job done and do it quickly.

memcached - written in C
postgresql - written in C
nginx - C
redis - C
sqlite - C
tokyocabinet - C
video games - most are C (i'm guessing here, not much of a gamer.)

See a pattern?

I haven't written a complete app in C or C++ in at least 10 years. I pretty much suck at it but I have this weird need get good. My plan is to grok the sources above and make it a point to code all my pet projects from here on out in C.

In other words, while standing on the shoulders of giants I'm going to build myself a stripped down track car with a 1000 HP engine. Sure, it will have manual brakes and steering, but it will go like hell. I hope it doesn't kill me.

3 comments:

  1. Please to write post in English next time. Thanks. xoxo

    ReplyDelete
  2. This comment has been removed by the author.

    ReplyDelete
  3. VB 3.0 was the pinnacle in the life of programming languages.

    ReplyDelete