When I saw the title, Clean Code, I immediately wondered whether it could help me organize my own code better. When I'm programming, especially under time constraints, my primary goal is to make the code work. Taking care of its appearance or ensuring that it will be easy to maintain is often an afterthought. This is true despite lots of experience with the difficulty of reading code that’s not well-structured and properly commented.
The foreword, introduction, and first chapter are a pleasure to read and highly motivating. The author—"Uncle Bob," as he calls himself—describes the problems that bad code generates, from the increased debugging effort to the time spent trying to understand legacy code. He also encourages programmers to learn how to maintain clean code, suggesting that we apply the Boy Scout rule: "Always leave the campground cleaner than you found it."
The main content is divided into three parts. Chapters 2 to 13 cover basic programming concepts with simple examples that illustrate how to write clean code. The chapters include advice on topics ranging from functions and comments to error handling and unit testing. They are easy to read and understand, and they provide a general idea of how to improve your programming style.
Chapters 14 to 16 offer complete examples and show how to use the advice in earlier chapters to refactor bad code into clean code. Two case studies deal with actual code from the JUnit testing framework and the JCommon library. I appreciated the use of two well-known libraries in the case studies, but the amount of code listings and cross-references pose a challenge for readers who must continually flip through the book's pages.
The final part of the book, and probably the most important, is Chapter 17. It summarizes all the book's bits of advice, or "coding rules." These rules are numbered and organized in several sections that provide a good overview of the book. The previous chapters had identifiers that referenced the rules enumerated in this chapter. However, I didn't like these forward references because the identifiers' meaning wasn't explained until this chapter. Therefore, I would have preferred Chapter 17 to come before the case studies. It would make them easier to follow.
All the code examples in the book are written in Java. However, the rules are valid for all programming languages, so non-Java programmers can also benefit from them. This book proves that code can always be cleaned up and that the process of doing so will be rewarding at the end.
Clean Code is written for programmers who want to improve their coding style. It should also be useful for programming teams wanting to establish some common basic rules to make their collaboration easier. Some experience is desirable to take full advantage of the advice. Students and novice programmers who have no experience working with large code bases probably won't fully understand the problems bad code causes.
Aída Jiménez is a researcher at the Intelligent Databases and Information System research group in the University of Granada's Department of Computer Sciences and Artificial Intelligence. Contact her at email@example.com.