A first set of refactorings
The eleven refactorings that *Refactoring* 2nd edition calls the most useful set (chapter 6).
Techniques
- Change function declaration
Change the name or the parameters of a function and update every caller, in one step when the callers are few and in stages when they are not.
core - Combine functions into class
Turn a group of functions that all take the same data into a class that holds the data, so that the shared context is explicit and the calls get shorter.
core - Combine functions into transform
Gather the calculations of values derived from a record into one function that takes the record and returns a copy with the derived values added.
core - Encapsulate variable
Put a widely used variable behind a function that reads it and a function that updates it, so that every access goes through one place that you can change.
core - Extract function
Move a fragment of code into a function of its own, named for what the fragment does, and replace the fragment with a call. The behaviour of the program does not change.
core - Extract variable
Give a part of a complex expression a name, by moving it into a local variable and using the variable in its place, so that the expression reads as the steps of a rule.
core - Inline function
Replace each call of a function with the body of the function, then delete the function, when the body says what the function does as clearly as its name.
core - Inline variable
Replace the uses of a local variable with the expression that it holds, then delete the variable, when the name says no more than the expression.
core - Introduce parameter object
Replace a group of parameters that travel together with one object that holds them, so that the group has a name and a place for the behaviour that belongs to it.
core - Rename variable
Give a variable a name that says what it holds, and change every reference in its scope, with care for names that are shadowed and for references that a tool cannot see.
core - Split phase
Split code that does two different things in sequence into two functions, joined by an intermediate data structure, so that each phase can be read, tested and changed alone.
core