The Art of Readable Code

The Art of Readable Code is a book by Trevor Foucher, Dustin Boswell in which they argue that

Code should be written to minimize the time it would take for someone else to understand it.

The focus in on code (i.e. mostly at the function level) rather than at a whole program but is packed with many examples and very easy to follow. The authors provide a large number advices for improving the readability of the code including:

  • naming (variables, functions, ...)
  • how to provide meaningful (non-redundant comments)
  • simplifying the control flow and expressions
  • structuring the code

To give you an idea of why these advices are important based on my personal experience as a teacher. When I am called by students to help them fix a bug in their code, we almost always rewrite their code (together) following very much the advices from this book. Without that, there is no way I can understand precisely what their code does (and whether it does what it was meant to). Usually, once we are done rewriting it, the bug becomes obvious (to me and most importantly to them as well).