230 likes | 366 Views
Predicting Classes in Need of Refactoring – An Application of Static Metrics Liming Zhao Jane Hayes lzhao2@uky.edu hayes@cs.uky.edu 23 September 2006 2006 International PROMISE Workshop. Predicting Classes in Need of Refactoring: An Application of Static Metrics. Motivation Related work
E N D
Predicting Classes in Need of Refactoring – An Application of Static MetricsLiming Zhao Jane Hayeslzhao2@uky.eduhayes@cs.uky.edu23 September 2006 2006 International PROMISE Workshop
Predicting Classes in Need of Refactoring: An Application of Static Metrics • Motivation • Related work • Design of the tool • Study design • Study results • Conclusions and future work
Motivation • Cost of software maintenance • Refactoring • Importance of refactoring planning • Need for improving multiple classes • Deadlines, human resources, budgets
Refactoring steps • Identify code segments • Evaluate possible costs and benefits • Develop refactoring plan • Apply the refactorings
Why use a class-based approach? • Common programmer(s) • Cohesive code • Learning effect • Comprehension overhead
Proposed approach Maintainability Measurement & Prediction Component (MMPC) Visualizer Code Repository Analysis Complexity Size Coupling History Maintainability Prediction Model Candidate Classes Cost-Benefits Estimation Cost Benefits Refactoring Planning PrioritizedClassList Managers Cost & Benefit Estimation Component (CBEC)
Design of the tool Code Repository Analysis Complexity Size Coupling History Maintainability Prediction Model CandidateClasses RefactoringPlanning
Related work: Maintainability assessment • OO metrics – Chidamber and Kemerer [1994] • MI – Welker [1995] • PM and MP – Hayes et al. [2004] • Assessment of UML artifacts - Hassan et al. [2005] • RDC ratio – Hayes and Zhao [2005]
Related work: Refactoring • Preconditions – Opdyke [1992] • Bad smells – Fowler et al. [1999] • Detecting bad smells – Mens et al. [2003] • Member similarity – Simon et al. [2001]
Metrics examined • Halstead metrics • Cyclomatic complexity • Weighted method per class • Maintainability index
Class-based rank • Cost concern • Priority class list • Individual rank • Comprehensive rank
Code repository analysis and metrics collection • Code repository analyzer • Java front end • Abstract syntax tree • Metrics • Complexity • Size • Other • Weighted maintainability rank (WMR)
Initial validation on student projects • Objective of the study • Measures examined • Tool’s performance • Programmers’ decisions • Tool vs. programmer • Time spent
Study design • Participants: Graduate students in computer science • Subjects: Java source code (20 classes) from software engineering class project • Pre-reading: Questionnaire about background, smell-list, etc.
Study design: procedure • Procedure instructed: • Fill in the questionnaire and read about the smell list • Read the code and look for “bad smells”; select a smell from a provided list or fill in a problem observed that was not in the list • Find the class with the most serious problems that should be refactored first • Record the time spent reviewing/reading each class
Study Result: Compare reviewers’ selection with tool’s selection • Legend of class name abbreviations: A - AnimationScreen, F-FileOutPut, L-LoginScreen, P- PitchAnalyzer, S- SessionReport, E- ErrorWindow, G-Graphic, LO - LoudnessAnalyzer, R- RegistrationScreen, T - TestScreen, F- FileInputHandler, H - HistoryReport, M - MenuScreen, W- Welcome, I1 – ImagePanel1, I2 – ImagePanel2, L – LoginScreen
Class Animation • Noted by 67% of the reviewers and the tool (ranked 1st by 50% of the reviewers and the tool) • Largest halstead_effort and smallest MI • Long method per class (LMC) and Complex method per class (CMC) above average (Slide 43)
Study results • Tool and half of reviewers noted class Animation as worst • Reviewers spent a significant amount of time (1-3 hours) • More “easy” problems found (90%) • Reviewers looked for different smells (28% not in list)
Conclusions • Complexity and size are among the major factors making comprehension hard • Reviewers are looking for different problems • Code reviewing is time-consuming • Automation can help consistency, efficiency, and effectiveness
Future work • Predict the possible cost of the refactoring and its impact on code maintainability • Use metrics from evolution history • Use metrics reflecting inter-class relationships
Acknowledgements • Thanks to Edison Design Group for providing JFE • Thanks to the graduate student volunteers for participating in the study