February 24, 2009

I get a kick out of clean code

Lately I’ve been on this kick about writing clean and readable code. Having recently read Clean Code by Uncle Bob, and having previously reveled in Ubiquitous Language from the blue book, my coding style has really changed. I find that I am much more conscious of not just what my code does, but what it says, and how it says it.

I’ve only been programming full-time for a short while now, just shy of 2 years, but I’ve been doing some programming here and there for close to 15. I have always been one to try and give my variables and procedures meaningful names and make the code as self-documenting as possible, but my recent stylistic evolution has transcended that.

I now strive to make my code read almost as a narrative. The tendency towards shorter, single purpose methods and classes and new language features (I write mostly in C#) allows construction of code that almost forms terse Hemingway-esque sentences. When I finish some code and I feel I can show it to a non-programmer domain expert and they can understand it and comment on it, I feel good about it.

I’m going to try to expound on this a bit more in some future posts, and give some examples of code I’ve written that I think illustrates what I’m trying to express.