Refactoring
A book by Martin Fowler
I recently finished this as part of a book club (I've covered it here and there with a few thoughts). While there are several key insights that made the book worth reading, I found much of the content redundant for someone with industry experience. For instance, a pattern like "extract function" is basic and straightforward: you take logic that fits together semantically and extract it into a separate function. Simple ideas like these made it difficult to find value at times. One section I found myself skipping was the "Mechanics" part of each chapter, which covers the step-by-step process for applying a recipe. These steps felt unnecessarily detailed and basic. The patterns themselves weren't particularly enlightening, safe for a few instances.
The most valuable takeaways for me were:
- The clear definition of refactoring as the process of improving the internal structure of the code without changing its observable behavior.
- The importance of having a strong test suite BEFORE the refactoring starts
Fowler's methodical approach might feel slow at times, but it prevents the pitfalls of large refactoring that can introduce regressions or breaking changes. Some intermediary steps feel very awkward but they are a mean to an end (which all comes together eventually, you just have to trust the process). Having this discipline comes with a reward, if you make a mistake your test suite will tell you right away, instead of after you're done refactoring. The book stresses that by testing frequently, hinting at the fact that, like most things, it takes some time to build the muscle memory (with the promise that it will actually be an effective methodology).
While the book provides good foundational knowledge, I feel it might be more suited for newer developers or those looking to formalize their understanding of good code structure. For someone with more experience, the book doesn’t offer many fresh insights. Some of the cataloged patterns are useful, but the time investment required to go through all of them might not be worthwhile.
In summary, I appreciate Fowler’s ability to distill common refactoring patterns into a cohesive framework. However, as someone who's been in the industry for a while, I didn't get as much value from the book as I might have six or seven years ago. Overall, I'd rate it 3 out of 5 stars. It's a good resource for those seeking more guidance on how to refactor code, but it’s not a book I would reread.