Known as “Uncle Bob” throughout the community, Robert C. Martin has already written numerous books about clean code. His publisher, Prentice Hall, even has an own Robert C. Marin series consisting of four of his most famous publications:
- Agile Principles, Patterns, and Practices in C#, 2006
- Clean Code: A Handbook of Agile Software Craftsmanship, 2008
- The Clean Coder: A Code of Conduct for Professional Programmers, 2011
- The Software Craftsman: Professionalism, Pragmatism, Pride, 2014
The second book in this series is a collection of advice and guidelines on how to improve existing code and how to write clean code in the first place. The book is about finding meaningful names, sensible function design and appropriate error handling. Uncle Bob gives advice on how to properly comment and format code, on how to design classes, data structures and whole systems. Each tiny chapter is able to improve your style of coding. Advanced developers, however, should take every “must-follow” guideline with a grain of salt. Sometimes the author is too dogmatic about his rules.
The last two chapters are in the style of Martin Fowler – real world examples instead of laboratory conditions. Described by the author as “the hard work of the book”, two sizeable components are being refactored. Step-by-step improvements using many of the previously presented guidelines are gradually transforming mediocre code into clean code. While every step is logical, the final product could benefit from further improvements. Reviewing the code with a colleague of mine turned up a lot of remaining code smells and the feeling that the refactoring process stopped too early. Although it has been a fun exercise for us, such a book should try to aim for more in its demo cases. The book closes with a list of code smells and useful heuristics.
Prerequisites? You should already have a profound programming knowledge and should at least know one of the “three big” OO languages: C++, Java or C# (the examples in the book are written in Java).
Should you read the book? Altogether it is a very interesting and educational book for prospective “clean coders”. Advanced developers should reflect on the given advice and try to improve example refactorings further than Uncle Bob does in the book – following the clean code boyscout rule: leave the code cleaner than you found it.
Final thoughts? Although I’m now at a point where I feel that books about clean code are not telling me too much news anymore, I’m definitely looking into the newer two books of Robert C. Martin as well, probably picking out selected chapters, maybe even reading them as a whole.