Refactoring - Word Analysis

What is it?
(verb) restructuring software preserving its observable behaviour
(noun) small, behaviour preserving transformation
not to be confused with
Refactoring preserves behaviour; rewriting often changes it
Refactoring incrementally changes existing code; rewriting usually replaces large sections from scratch
We can release code in the middle of a refactoring; rewriting tends to be an "all or nothing" situation
Refactoring can start with little design up-front; rewriting normally requires more design in advance
"[Refactoring] is revision, but it isn’t doing the work over." (Ron Jeffries)
How & When?
"identifying a specific problem with code, envisioning how to improve it, then improving it in small, reversible steps" (JB Rainsberger)
catalog of code smells
catalog of refactorings
Mikado method
Three strikes and you refactor.
Done continuously, as part of implementing a feature
We take the next feature that we are asked to build, and instead of detouring around all the weeds and bushes, we take the time to clear a path through some of them (Ron Jeffries)
No "refactoring stories" in the backlog
Reasons to do this crazy thing
Reducing volatility in the cost of new features (JB Rainsberger)
Work experience versus Refactoring to Design Patterns: A Controlled Experiment (Ng, 2006)
To complete a maintenance task of perfective nature, the time spent even by the inexperienced maintainers on a refactorized version is much shorter than that of the experienced subjects on the original version
Are Refactorings Less Error-prone Than Other Changes? (Weißgerber, 2006)
Although we found interesting correlations between refactorings and bug reports, we are aware that these could be accidental or caused by other factors.
On the Relation of Refactoring and Software Defects (Ratzinger, 2008)
we discovered that refactorings and defects have an inverse correlation: The number of software defects decreases, if the number of refactorings increased in the preceding time period
A Field Study of Refactoring Challenges and Benefits (Kim, 2014)
refactoring changes are likely to be relatively more reliable than regular changes in a large system
The refactoring definition in practice seems to differ from a rigorous academic definition of behavior-preserving program transformations
survey participants perceived that refactoring involves substantial cost and risks
significant reduction in the number of inter-module dependencies and the number of post-release defects.
field use
How We Refactor, and How We Know It (Murphi-Hill, 2009)
most refactorings are performed in batches, repeating similar refactorings
Commit Messages don't predict Refactorings. We suspect this because refactoring may be an unconscious activity
programmers frequently "floss refactor", that is, they interleave refactoring with other types of programming activity, to keep the code healthy.
About half recactorings are Medium and Low-level
High level refactorings are those that change the signatures of classes, methods, and fields
Medium level refactorings are those that change the signatures of classes, methods, and fields and also significantly change blocks of code
Low level refactorings are those that make changes to only blocks of code
refactorings are performed frequently
he kind of refactoring performed with tools differs from the kind performed manually
impact on Quality
Empirical investigation of refactoring effect on software quality (Alshayeb, 2008)
We found that refactoring improved a quality attribute in some classes, only to reversely weaken that same quality attribute in other classes of the same system. We thus are unable to validate that refactoring as a whole practice improves software quality.
An Empirical Assessment of Refactoring Impact on Software Quality Using a Hierarchical Quality Mode (Shatnawi, 2011)
different refactorings impact quality factors in different ways, some improving quality and some deteriorating quality
Reusability is the quality factor that has the largest number of positives (65%). This tells us that most refactoring activities change classes to have the appropriate responsibilities and make the design more reusable.
The effectiveness improves for 42% of the refactorings, whereas it deteriorates for 9% only.
The refactorings improve flexibility and extendibility of a system more than otherwise
most refactoring heuristics improve the four quality factors.
developers can use particular refactorings to improve particular aspects of quality (goal-driven refactoring heuristics)
An Empirical Evaluation of Impact of Refactoring On Internal and External Measures of Code Quality (Kannangara, 2015)
The result of external measures did not show any improvements in code quality after the refactoring treatment. However, from internal measures, maintainability index indicated an improvement in code quality of refactored code than non-refactored code and other internal measures did not indicate any positive effect on refactored code.
Results seem "statistically inconclusive"
Essential Books
"Refactoring: Improving the Design of Existing Code", by Martin Fowler
"Refactoring to Patterns", by Joshua Kerievsky
"Refactoring Databases: Evolutionary Database Design", by Scott Ambler
"Refactoring Workbook", by WIlliam Wake