This is the associated notes and list of references for my Tips and Tricks for Refactoring JavaScript Applications talk. Interested in having me present this at your meetup? Email me at brandon at brandonmorrison dot com.
What is Code Refactoring?
Refactoring: a change made to the internal structure of software to make it easier to understand and cheaper to modify without changing its observable behavior.
Intentional code changes that don’t affect an applications outside behavior.
We do this for a few reasons…
- Makes Code Easier to Understand
- Helps You Find Bugs
- Makes Adding New Features Easier/Faster
What Do I Need to Get Started?
Refactoring a codebase is a team sport. Making anything beyond trivial changes to a codebases needs coordination with your entire team to ensure that everyone is on the same page.
General Strategies
- Keep it Simple & Incremental
- Target Areas Where Frequent Changes Are Needed
- Test and Commit Often
- Don’t Overdo It!
Selling/Calculating ROI for Refactoring
Every situation is going to be different. In organizations that have leaders with strong engineering backgrounds, the question might not be “Should we our code at all?” but “When and which parts of our code should we refactor?”
In general, the choice to refactor parts of a codebase boils down to what is the return on investment of refactoring said code.
References
Tools
https://code.visualstudio.com/docs/editor/refactoring
https://marketplace.visualstudio.com/items?itemName=cmstead.jsrefactor
https://www.jetbrains.com/help/webstorm/specific-javascript-refactorings.html
Convincing Your Boss
http://qualilogy.com/en/legacy-application-technical-debt-roi-refactoring/
https://stackoverflow.com/questions/1790431/how-do-you-estimate-a-roi-for-clearing-technical-debt
https://blog.carbonfive.com/2019/05/22/taming-technical-debt/
https://medium.com/s/story/technical-debt-is-like-tetris-168f64d8b700
Reference Books
Refactoring: Improving the Design of Existing Code By Martin Fowler
JavaScript Patterns By Stoyan Stefanov
Growing Object-Oriented Software, Guided By Tests by Steve Freeman and Nat Pryce
Refactoring (Ruby ed): https://martinfowler.com/books/refactoringRubyEd.html
Ruby Patterns: https://www.amazon.com/Design-Patterns-Reader-Addison-Wesley-Professional-ebook/dp/B004YW6M6G
Practical Object-Oriented Design: https://www.poodr.com