Book Review: Refactoring TypeScript
My latest pick from Packt's recent book releases was Refactoring TypeScript by James Hickey. It's a rather short book that I liked much better than my previous choice. It doesn't seem to be mentioned often although it's already been available for a couple of months. I think it deserves more attention.
The author starts with a brief introduction, making a case for continuous refactoring. The following quotes summarize it well:
Leave the code cleaner than you found it.
Refactoring isn't a special task that would show up in a project plan. Done well, it's a regular part of programming activity.
What I liked most about the book is its hands-on approach. Each chapter starts with a code snippet featuring some problems that make it difficult to understand and maintain (code smell, as the author puts it). I'm certain that these will be familiar to any experienced developer. The rest of the chapter focuses on actionable step-by-step improvements that can be applied to the code to make it better.
In the process, a couple of well-known software design patterns are presented (e.g. strategy, command, factory method, builder), but they aren't the focus of the book. They aren't even thoroughly explained. Instead, they are simply used pragmatically, as a natural progression of the incremental improvements that were already applied to the code. It's up to the reader to learn more about these design patterns from other sources if he's interested.
As one could expect based on the title of the book, all of the code samples are written in TypeScript. However, the concepts presented are more generally applicable and not language specific. Yes, in other languages the suggested refactorings might need to be implemented a bit differently, but that doesn't mean you won't benefit from the book. I would recommend it to any developer who can fluently read JavaScript/TypeScript (or any other C-based language).
The book is available in the Packt subscription, but you can also buy it from Amazon.