Book review - The Art of Readable CodeSat, Dec 31, 2011
In my recent visit to the Computer History Museum I had a few hours to pass on a flight from San Jose to Seattle, and I spent it with a new book in the genre of ‘self help for programmers’
It’s a really easy read in 14 clean (and short) chapters:
- Code should be easy to understand
- Packing information into names
- Names that can’t be misconstrued
- Knowing what to comment
- Making comments precise and compact
- Making control flow easy to read
- Breaking down giant expressions
- Variables and readability
- Extracting unrelated subproblems
- One task at a time
- Turning thoughts into code
- Writing less code
- Testing and readability
As a fairly experienced developer, I found it mostly a review of ideas and patterns I have already come to agree with, that the author sums up nicely as:
Code should be written to minimize the time it would take for someone else to understand it
I don’t always succeed in that with my own code, but the further I get in my career, the more I appreciate just how important it is to write code that can be understood, maintained, and enhanced by others.
As such, I pretty much agree with all of the author’s points, and one piece of advice I was particularly happy to see:
Naming Test Functions - Don’t be afraid of having a long or clunky name here. This isn’t a function that will be called throughout your codebase, so the reasons for avoiding long function names don’t apply. The test function name is effectively acting like a comment.
I am usually aggressive about short, but meaningful, names… except when it comes to my unit tests when I sometimes go a little crazy with long descriptive test names, so its nice to read something that helps me understand why I do that!
When I’m learning something new (such as the Android platform), I’ll surround myself with books about that specific technology, but in general I much prefer these kinds of ‘make yourself a better programmer’ books.
If you like these kinds of books, (you are a programmer, right ?), then don’t forget to check out these similar titles:
- Code Complete - Steve McConnell
- The Pragmatic Programmer - Andrew Hunt & Dave Thomas
- The Passionate Programmer - Chad Fowler
- Clean Code - Robert C. Martin
- Beautiful Code - Andy Oram
- The Practice of Programming - Brian W. Kernighan & Rob Pike
- Programming Pearls - Jon Bentley
… and I assume you already own at least 2 copies of the first one on that list :-)