Refactoring JavaScript Notes

Originally published on , last updated on .

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. -Martin Fowler

In other words, intentional code changes that don't affect an applications outside behavior.

We do this for a few reasons...

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

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://softwareengineering.stackexchange.com/questions/21538/best-supporting-argument-for-refactoring

https://www.hbs.edu/faculty/Publication Files/2016-JSS Technical Debt_d793c712-5160-4aa9-8761-781b444cc75f.pdf

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