This Is AuburnElectronic Theses and Dissertations

An Extract Function Refactoring for the Go Language




Gnanaprakasa, Steffi Mariya

Type of Degree

Master's Thesis


Computer Science


Refactoring is a disciplined technique for restructuring an existing body of code, altering its internal code structure without changing its external behavior. Refactoring is specified as a parameterized program transformation that requires a set of preconditions to be satisfied. The Go Doctor is a refactoring tool for the Go language. This thesis focuses on the design and implementation of an Extract Function refactoring adapted to the unique requirements of the Go language. The code that is to be refactored is parsed and type checked before the process is initialized. The tool ensures that certain preconditions are met; if they are not, it warns the user with the exact details as to why the refactoring will not continue. Then, a Live Variable analysis is used to determine what variables need to be passed to, returned from and declared in the new function that is created from the extracted code. To analyze the robustness of the refactoring, it was applied to 200 random statements selected from the top 100 GitHub projects using Go. These projects were also used to assess the potential impact of some of the refactoring limitations - specifically, its inability to extract return statements, defer statements, and anonymous functions.