Wednesday, April 9, 2008

More insights into the zen of programming

As a programmer (or "software developer", as it says on the business card) you're always impressed by cool quotes. It might not be the 90s anymore, but the really cool quotes still come from Linux kernel developers. Check this one out. In case you're too lazy to click the link, here's the important line: "inline is the register keyword for the 21st century".

I haven't researched this, but if Rusty Russell says so, I'm inclined to believe it. Basically, the compiler knows more about register allocation than you do, and these days, it also knows more about inlining than you do. The "inline" keyword has always made me feel a bit uneasy, and these days, it's next to impossible to keep track of how inlining affects performance. But we have powerful AI engines that take care of worrying about that kind of stuff, and they're called compilers.

Both you and me know that compilers don't know everything. In extreme circumstances it pays off to read a disassembly (from one particular target platform) of the code it produces, but we should all know better than to optimize without using tools to measure the improvements. Profilers have been around forever. The message is: don't inline without profiling with and without the inline keyword. Don't turn functions that you think are used a lot into messy macros. Use your head, and let the tools take care of the things that your head can't cope with. One of the things that your head can't cope with is writing C code that the compiler can turn into good stuff on an almost infinite range of target architectures.

I can't believe I just said that. But this isn't the 80s anymore.

1 comment:

Simon said...

Dude. Soon you'll be saying things like: "Today's compilers are much better at memory allocation than you are. Compilers for high-level languages such as Standard ML and Erlang produce much more efficient code than C. malloc() is the inline for the 2010s."

When you start thinking thoughts like that, give me a call, ok? I'll talk to my friends in Malmö and have them check up on ya. Take care!