Book Review – Clean Code by Robert C. Martin

Clean Code by Robert C Martin

Let me start by saying that I highly recommend this book to anyone writing code who wants to learn to write better, cleaner code.

What the Book Covers

Chapter 1 Clean Code – Different authors of programming books give their take on what their idea of clean code is as they try to help you become a good programmer.

Chapter 2 Meaningful Names – Gives you a break down of what to try to avoid calling method names, variables, and such like and helps you to try to use meaningful names as is the chapter name.

Chapter 3 Functions – Hints that functions should be small and that they should only do one thing and do that one thing well and gives examples of poor functions and how to refactor them in to new functions which have one function. Again I think this is a particularly good idea even though sometimes not always practical.

Chapter 4 Comments – Before I read this book I would normally add a comment the code I was working on but after reading this chapter I realised that comments in your code can be bad. It’s better to try to write self documenting code and try not to litter your code with comments, how many times have you changed code and then changed the comment of the author who wrote the code in the first place (hats off if you always do that everytime, including stored procs?), so code with the wrong comments can lead to issues themselves.

Chapter 5 Formatting – Covers different types of formatting your code as well as indentation and is pretty irrelevant with Visual Studio and such editors.

Chapter 7 Error Handling – Returning Null is bad but passing Null into a method is worse – code with endless checks for Null should be refactored – yep have to agree.

Chapter 9 Unit Tests – Covers the concepts of how to write good unit tests.

These are just a few hand-picked chapters which I thought were very good indeed.

Summary
This book is my favourite book, even ahead of Code Complete which I thought was an excellent book in its own right. Keep your code simple, use meaningful names and don’t use comments when there is no need to.

It’s the kind of book you will go back to again and again and there aren’t that many books which you don’t mind reading cover to cover again.

I’m sure you will enjoy this book and definitely learn something.