Kernel Coding Style

by Jonathan

I came across the kernel coding style page while browsing open source security utilities. I’ve bounced between styles quite a bit this year, even from assignment to assignment, and it doesn’t help that I’ve used C, Java, Haskell, Racket, Prolog and PHP just this term. Fiddling with my vimrc file makes things worse, as I constantly find myself frustrated with alignment in other text editors and github. But I’d like to use a consistent coding style, even if it’s not kernel coding.

Brace placement varies more than anything amongst people I’ve coded with. Lately I’ve been putting every single brace on it’s own line, thinking this was the true way of C. Linus has shown me otherwise:

“as shown to us by the prophets Kernighan and Ritchie, […] put the opening brace last on the line, and put the closing brace first”

K&R are indeed prophets, so I’m sold on this. I’m not fond of using 8-space tabs, though. But there’s some interesting rationale behind that choice:

“if you need more than 3 levels of indentation, you’re screwed anyway, and should fix your program.”

I’m tempted to use 8-spaces just to remind myself of that. Favor simplicity, the core of UNIX programming. I guess WordPress can’t handle gist. Actually, there’s not much it can do. I guess I’d need my own blog for any real support. Anyway, take a look at the gist to see what I’m talking about.