Dustin Boswell, Trevor Foucher, "The art of readable code"

Dustin Boswell, Trevor Foucher, “The art of readable code”

There are plenty of books published about writing code. Thus I was skeptical after a friend of mine showed me yet another one. To my surprise, without a long introduction it went straight to the point and coined the following statements right in the first chapter:

  • Code should be easy to understand.
  • What make code “better”?
  • The fundamental theorem of readability.
  • Code should be written to minimise the time it would take for someone else to understand it.
  • Is smaller always better?
  • It is better to clean and precise that to be cute.

The style of the book was precise and concrete. I felt that in less than two hundred of pages it’s quite ambitious to cover the subject of “the art” and decided to order the book to find out how they’re going to do that.

Eventually, a few hours of reading on weekend were worthy. Though an experienced programmer will barely find any eye openings in the book, but surprisingly, this is a compact, concise and solid handout for juniors. Without too much theory, always using real examples, the authors go through many key points of writing code: how to name variables, functions and classes, how to structure the code, how to deal with efficiency-readability trade off, how to comment, where to compromise and where be a perfectionist. Again, it’s all in less then two hundred pages. Plus they briefly touched unit testing.

The authors not only tell you what is good and bad, they always demonstrate “why” on examples gradually improving “regular” code. At the end they put a real example of a class counting network traffic and returning a number of bytes transferred in the last hour and day.

They began with a naive implementation and then worked through two more versions showing that sensitive balance between efficiency and readability. I think that even experienced developers may find this example interesting to play with.

To sum up, this book can fit perfectly into your team book shelf and be used as a quick reference of how-tos. Buying for yourself is questionable, because at home you’d probably prefer something more fundamental.


Disclaimer

Comments