Friday, February 8, 2013

coding_style

A brief history of my coding style.

The first language I learned was Java, so my style was, more or less, K&R with camelCase.  Overtime, I gotSickOfCamelCase in_favor_ of_underscores.  (Pro-tip: check out xmodmap for Linux and BSD machines.  I've mapped Shift+Spacebar to underscore, which makes my life, and my carpel tunnels, so much happier).


Most people consider this the holy grail of coding styles, and for good reason.  The nethack and slashem source is written in the K&R style, though the indentation is poor:



I don't have OCD.  My room's a mess, I have a few weeks worth of scruff grown on my face, but poor and/or inconsistent indentation and coding style drives me fucking crazy.  It's a trait my parents wish I had in every other aspect of my life, but only made it to programming and guitar playing.  I NEED it to be perfect, and though it never is (including my own code), I try to get it as close as possible.

Recently, I've changed my coding style a bit.  I've strayed from K&R in favor of an unnamed style. Below is an example of my new coding style, taken from a memory manager I wrote for a kernel driver.  On one hand, it wastes vertical space (an aspect K&R handles very well) but it's much easier for me to read.  Maybe you younguns out there disagree, but I've found that, as I've gotten older, I prefer a style that's easier on my 27 year-old eyes.  Note the extra space within parentheses.  Check out line 146 for my favorite pointer trick.



Complicated conditionals are


Are we having fun yet?

1 comment: