I decided to publicate occasionally reviews of interesting books that I read. So this is the first one, review of “Refactoring: Improving the Design of Existing Code” book written by Martin Fowler in cooperation with few others famous programmers.
Article is also available in Polish version.
What the book is about
Who of us hasn’t met spaghetti code, mixed dependencies, functions with hundreds of lines or problems with introducing new simple feature to our code. I believe that there is no programmer in the world who has never met this dubious pleasure. This situation is result of multi-month or multi-year negligence of the code by development team. This usually means that in order to add new functionality, you modify or add additional lines or conditional instructions to your existing code. When the situation repeats many times, arise code, that everyone is afraid to touch and modify because of fear of corrupting already functioning features. If we are in this situation it means that we’ve forgotten the tool called refactoring.
A book using many examples provides an easy way to explain how to recognize bad code examples, and shows how to improve it to make it easier, more readable, and more susceptible to change.
Fowler presents a sequence of transformations that must be performed to modify the existing code for new requirements in safely way. At the same time he emphasizes the role of unit tests and their impact on the success of all operations.
The book introduces a term called code smells, which are nothing but the symptoms. We should think about refactoring if we start to notice or feel ones in our code. It is important that this should be carried constantly according to the so-called “scout principle”. This rule says that if we are entering a code while working on a task, we should try to leave it in a better condition than we found it.
Examples have been written in Java language but I think programmers which works with other languages shouldn’t have any problem with understanding them.
The code smells that Fowler describes we can mention:
- duplicated code,
- long method,
- large class,
- long list of parameters,
- feature envy,
- lazy class,
- switch instruction,
- and so on.
I invite you to read the book for more details.
In my opinion, the book is worth the attention and every self-respecting developer should be familiar with it. It’s not a beginner’s book, but if we’ve written a few thousand lines of code in our lives, we’ll definitely appreciate the advices that Fowler wants to give us. If you haven’t read it yet, I would recommend it for you.
I rate this book at well-deserved 5/5 grade because it was very inspirational and I’ve learned a lot from it. Mandatory position for me.