Refactor Like a Superhero
It is a book about how to refactor code efficiently and without pain. In it, we will discuss the benefits of refactoring for development and business and explore ways of searching for problems in code and fixing them.
What It Covers
This book covers various topics from the most obvious, like naming and code linters, to more fundamental, like regressions, high coupling, leaky abstractions, code complexity, and poor architecture.
We will explore some of the “programming buzzwords” and discuss how they can help us improve the code and make the refactoring process easier.
Table of Contents
The book contains 21 chapters and 2 appendices with a list of references and a cheat sheet with short recommendations.
- Preface
- Introduction
- Before Refactoring
- During Refactoring
- Low-Hanging Fruit
- Names
- Code Duplication
- Abstraction
- Functional Pipeline
- Conditions and Complexity
- Side Effects
- Error Handling
- Module Integration
- Generics, Inheritance, and Composition
- App Architecture
- Declarative Style
- Static Typing
- Refactoring Test Code
- Comments and Documentation
- Refactoring as a Process
- Afterword
- Cheat Sheet on Refactoring Techniques
- Sources and References
Code Examples
We will use code examples primarily in JavaScript and sometimes in TypeScript.
However, the technics we’re going to discuss can be used in other high-level languages as well. So if you don’t code in JS/TS but feel comfortable around them, you might find something you can adopt to your language.
Language and Translations
The book is available in English and Russian. The complete list of currently WIP translations is available on GitHub.
If you are interested in translating the book into another language, please, contact me. I will be happy to discuss the details!
Download Ebook
You can also download the book in PDF or Epub format:
The ebook is distributed under the same license as the original. You can learn more about the terms and conditions in the last section of this page.
Feedback and Errata
The sources of the book are also available on GitHub. If you found a typo or have ideas for improvement text or code samples that would better describe the point, please send me an issue or a pull request. The history of changes and updates is also available in the book repository.
I hope you find the book helpful! If you like it, give it a ⭐️ on GitHub and share the link with other developers who might want to read it!
About Author
Hi! I’m Alex 👋
I’m a developer, speaker, and mentor. Currently working at 0+X and living in Stockholm.
Since 2010, I’ve been helping companies develop, release and maintain their projects; mentoring and teaching students software development; sharing my knowledge and experience through online books like the one you’re reading now.
If you’re interested in more educational projects like this one, check out my blog and follow me on Twitter.
License and Copyright
All materials are © 2022 Alex Bespoyasov. The work is licensed under the Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International License.
You are free to share the book and its contents if you don’t modify it and keep the authorship. You are not allowed to use these materials in commercial products.