{"id":12251,"date":"2019-08-27T16:10:48","date_gmt":"2019-08-27T13:10:48","guid":{"rendered":"https:\/\/mozaicworks.com\/?p=10837"},"modified":"2022-02-01T18:42:52","modified_gmt":"2022-02-01T16:42:52","slug":"a-new-method-for-fast-refactoring-of-legacy-code","status":"publish","type":"post","link":"https:\/\/mozaicworks.com\/software-engineering\/a-new-method-for-fast-refactoring-of-legacy-code","title":{"rendered":"A new method for fast refactoring of legacy code"},"content":{"rendered":"\n

In this article, I will present a method that I’ve tried in a few codebases in compiled languages for safely and quickly refactoring untested code. First, we will discuss the main problem we are trying to solve, quickly introduce the techniques coined by Michael Feathers, then discuss some shortcomings of the existing techniques, and finally describe the proposed technique.<\/p>\n\n\n\n

Briefly, the technique I’ve been experimenting with implies refactoring first towards pure functions using safe, mechanical refactoring steps, then testing the pure functions by quickly writing data-driven tests, property-based tests or by using the golden master technique, and finally refactoring the pure function towards the desired design. <\/p>\n\n\n\n\n\n\n\n

Please feel free to skip to the section “A New Method” if you are familiar with the legacy code problem and techniques. <\/p>\n\n\n\n

The Problem<\/h2>\n\n\n\n

Many software projects go through a cycle like the following:<\/p>\n\n\n\n