Here are some examples of micro-refactorings; some of these may only apply to certain languages or language types. A longer list can be found in
Martin Fowler's refactoring book and website. Many development environments provide automated support for these micro-refactorings. For instance, a programmer could click on the name of a variable and then select the "Encapsulate field" refactoring from a
context menu. The IDE would then prompt for additional details, typically with sensible defaults and a preview of the code changes. After confirmation by the programmer it would carry out the required changes throughout the code.
Static analysis Static program analysis (called "linting" when performed on less strict interpreted languages) detects problems in a valid but substandard program. •
Program dependence graph - explicit representation of data and control dependencies • System dependence graph - representation of procedure calls between PDG •
Cyclometric complexity analysis. •
Software intelligence - reverse engineers the initial state to understand existing intra-application dependencies
Transformations Transformations modify the syntactic representation of a program. Some modifications alter the semantics or structure of the program in a way which improves its flexibility or robustness. Such modifications require knowledge of the problem domain and intended logic, and thus are infeasible to automate. Modifications exist which make the program easier to read and modify but which to not alter the underlying logic of the program; these transformations can be automated. • Techniques that allow for more
abstraction •
Encapsulate field – force code to access the field with getter and setter methods •
Generalize type – create more general types to allow for more code sharing • Replace type-checking code with state/strategy • Replace conditional with
polymorphism • Techniques for breaking code apart into more logical pieces • Componentization breaks code down into reusable semantic units that present clear, well-defined, simple-to-use interfaces. •
Extract class moves part of the code from an existing class into a new class. • Extract method, to turn part of a larger
method into a new method. By breaking down code in smaller pieces, it is more easily understandable. This is also applicable to
functions. • Techniques for improving names and location of code • Move method or move field – move to a more appropriate
class or source file • Rename method or rename field – changing the name into a new one that better reveals its purpose • Pull up – in
object-oriented programming (OOP), move to a
superclass • Push down – in OOP, move to a
subclass ==Hardware refactoring==