This book is basically split in to two things: organizing your code so that it’s easy to read and following “good” OO practices. A great deal of the information presented in Clean Code is Robert C. Martin's personal preference, he’s very upfront about that, and what he has to say throughout the book makes a lot of sense.
The first part of the book makes it seem like writing clean code is relatively simple:
- Use unambiguous names for variables and methods.
- Comments should say things that the code can't say for itself.
- Keep methods small.
- Write unit tests.
Organizing your code as the author suggests, will make it very easy to read.
The trickier part has to do with the OO principles that are covered.
Knowing when you've violated SRP, OCP or if your methods have multiple levels of abstraction can be more difficult.
Fortunately, there are some nice examples in the book that the author walks you through. This is something that is clearly going to take practice and discipline to master.
All of the examples are in Java. I use C# at work, so I converted the examples to C# and refactored them alongside him. I found this to be very helpful.
In addition to covering the importance of unit testing and the role it plays in keeping your code clean, the author has listed all of the advice at the end of the book. This makes for a handy reference to ensure that you are writing clean code and is listed under the heading “Code Smells”. The list includes advice from the author as well as Martin Fowler.
I enjoyed the book and look forward to mastering the techniques that were covered.
* Update *
I found a video clip of Robert Martin where he presents a lot of the points in this book.
It's a little under an hour long and despite the fact that he rambles a little bit for the first 8 or 10 minutes, it's worth watching.
No comments:
Post a Comment