The Art of Readable Code: Simple and Practical Techniques for Writing Better Code
By Dustin Boswell and Trevor Foucher
(O’Reilly, paperback, list price $34.99; Kindle edition, list price, $27.99)
The software world is full of bad code.
Code that was badly written; code that has been reworked — badly — by dozens of undisciplined programmers; code written in haste to patch or hide a problem; code written without comments that can help you decipher what the previous programmer was thinking — or not thinking; code written by people like me, who didn’t know much at all about programming but had to produce some emergency code anyway, because the real programmers were away on vacation.
The Art of Readable Code could be a very useful book to give the programmer in your life — whether he or she is new to computer programming or an open-minded mid-career professional looking to make some improvements in how they work.
The book focuses on “basic principles and practical techniques” that programmers can apply each time they begin a new coding project or find themselves patching an old one.
The authors present what they call their “Fundamental Theorem of Readability.” In their view: “Code should be written to minimize the time it would take for someone else to understand it.”
For example, “smaller” may not always be better. A one-line expression may be more understandable to other programmers if it is broken into two lines of code.
The Art of Readable Code has 15 chapters and an appendix and is structured in four parts:
- Part 1: Surface Level Improvements – (Naming, commenting and aesthetics that can be applied to every line of code)
- Part 2: Simplifying Loops and Logic – (Refining loops, logic, and variables so they are easier to understand)
- Part 3: Reorganizing Your Code – (Higher-level ways to organize large blocks of code and go after problems at the function level)
- Part 4: Selected Topics – (Applying “easy to understand” to software testing and to a larger data structure coding example)
The authors state: “It’s a valuable skill to be able to explain an idea ‘in plain English….The same skill should be used when ‘presenting’ code to your reader. We take the view that source code is the primary way to explain what a program is doing. So the code should be written ‘in plain English.'”
The book itself is smoothly written and nicely illustrated, not only with cartoons but with some very clear code examples that can be quickly applied.
— Si Dunn