640 likes | 794 Views
Code Smell Research: History and Future Directions. Nikolaos Tsantalis Computer Science & Software Engineering. Preventive Software Maintenance. Changes aiming to improve the future maintainability and reliability of the software system. Why is it so necessary?. Software aging.
E N D
Code Smell Research:History and Future Directions Nikolaos Tsantalis Computer Science & Software Engineering Second PLOW Installment - March 5, 2014
Preventive Software Maintenance Changesaiming to improvethe futuremaintainabilityand reliabilityof the software system. Why is it so necessary? Second PLOW Installment - March 5, 2014
Software aging Refactoring
The Genesis 1992 • Refactoring Object-oriented Frameworks, University of Illinois at Urbana-Champaign • Introduced the concept of refactorings as behavior-preserving program restructuring operations. • Introduced the concept of preconditions as conditions that should be examined to determine whether a refactoring can be applied safely. Second PLOW Installment - March 5, 2014
The Past 1999 Second PLOW Installment - March 5, 2014
Martin FowlerRefactoring Duplicated Code: “If you see the same code structure in more than one place, … find a way to unify them.” Second PLOW Installment - March 5, 2014
The Past 2001 1999 Second PLOW Installment - March 5, 2014
Frank Simon, Claus LewerentzMetrics Based Refactoring CSMR Most Influential Paper Award Second PLOW Installment - March 5, 2014
The Past 2002 2001 1999 Second PLOW Installment - March 5, 2014
Eva van Emden, Leon MoonenAssuring Software Quality by Code Smell Detection WCRE Most Influential Paper Award jCosmo Second PLOW Installment - March 5, 2014
The Past 2003 2002 2001 1999 Second PLOW Installment - March 5, 2014
Tom Tourwé, Tom MensLogic Meta Programming Code smell definition for Inappropriate Interface inappropriateInterface(?class,?interface,?subclasses) :- findall(<?itf,?scs>, commonSubclassInterface(?class,?itf,?scs), ?result), removeDuplicates(?result,?nodups), member(<?interface,?subclasses>,?nodups) Second PLOW Installment - March 5, 2014
The Past 2005 2003 2002 2001 1999 Second PLOW Installment - March 5, 2014
RaduMarinescuDetection Strategies Second PLOW Installment - March 5, 2014
The Past 2008 2005 2003 2002 2001 1999 Second PLOW Installment - March 5, 2014
Mel O’Keeffe, Mel Ó CinnéideSearch-based Refactoring • Treat the improvement of object-oriented design as a search problem in the space of alternative designs • The movein the search space is achieved by modeling refactorings (inheritance-related) • Apply search algorithms using QMOOD as the fitness function (rank alternative designs) • The outcome is a sequence of refactoringsleading to the optimal design Second PLOW Installment - March 5, 2014
The Past 2009 2008 2005 2003 2002 2001 1999 Second PLOW Installment - March 5, 2014
NaouelMoha, Yann-GaëlGuéhéneucDECOR Second PLOW Installment - March 5, 2014
F. Palomba , G. Bavota, M. Di PentaHIST Why don’t we use historical information to find code smells? ACM Distinguished Paper Award ASE 2013 Second PLOW Installment - March 5, 2014
Code smells + Change history Many code smell definitions are based on historical change information • Shotgun Surgery: When every time you make a kind of change, you have to make a lot of little changes to a lot of different classes. • Parallel Inheritance Hierarchies: When every time you make a subclass of one class, you also have to make a subclass of another. Patterns of changes repeated over time Second PLOW Installment - March 5, 2014
Association Rule Discoveryin the Change History Second PLOW Installment - March 5, 2014
Aiko Yamashita, Leon MoonenInter-smell Relations What are the interactions among code smells and how they affect maintenance? ICSE 2013 Second PLOW Installment - March 5, 2014
Empirical Study design • 12 code smells • 6 Professional developers were hired to implement change requests • 4 medium-sized Java systems with known code smells • 4 weeks of development • Daily interviews and think-aloud sessions Second PLOW Installment - March 5, 2014
Code Smell Relationships Second PLOW Installment - March 5, 2014
The Other Side of the Coin Refactoring Opportunities Code Smells LIMITATION Second PLOW Installment - March 5, 2014
Refactoring Opportunities Advantages: • Feasibleand behavior preserving solutionsto design problems • Ranking and prioritizing solutions based on their expected effect on design quality • A holisticapproach for preventive maintenance Second PLOW Installment - March 5, 2014
Holistic solution TSE 2004 • Identify places where software should be refactored (known as bad smells). • Determine which refactoring(s) should be applied to the identified places. • Guarantee that the applied refactoring preserves behavior. • Apply the refactoring. • Assess the effect of the refactoring on quality characteristics of the software. • Maintain the consistency between the refactored code and other software artifacts. Second PLOW Installment - March 5, 2014
The history of refactoring opportunities 2009 Second PLOW Installment - March 5, 2014
#1 Misallocatedbehavior in classes Tsantalis & Chatzigeorgiou IEEE TSE, 2009 Second PLOW Installment - March 5, 2014
The history of refactoring opportunities 2009 2010 Second PLOW Installment - March 5, 2014
#2 Conditional logicvs. Polymorphism state StateA StateB Context Context State • + method() { • state.method(); • } • + method() { • } +method() { } +method() { } +method() - type : int -STATE_A : int = 1 -STATE_B : int = 2 -state : int -STATE_A : int = 1 -STATE_B : int = 2 • ifstate== STATE_A • else • ifstate== STATE_B • doStateA(); • doStateB(); Tsantalis & Chatzigeorgiou JSS, 2010 Second PLOW Installment - March 5, 2014
The history of refactoring opportunities 2009 2010 2011 Second PLOW Installment - March 5, 2014
#3 Long & Complex methods Tsantalis & Chatzigeorgiou JSS, 2011 Second PLOW Installment - March 5, 2014
The history of refactoring opportunities 2009 2010 2011 2012 Second PLOW Installment - March 5, 2014
#4 Large & Complex classes 19 methods 11 fields 70 methods 15 fields 900 LOC Bavota et al. JSS, 2011 Fokaefs et al. JSS, 2012 Second PLOW Installment - March 5, 2014
The history of refactoring opportunities 2009 2010 2011 2012 2013 Second PLOW Installment - March 5, 2014
#5 Generalization of common interfaces or functionalities Liu et al. AutomSoftwEng, 2013 Second PLOW Installment - March 5, 2014
The history of refactoring opportunities 2014 2009 2010 2011 2012 2013 Second PLOW Installment - March 5, 2014
#6 Software Clones Krishnan & Tsantalis CSMR-WCRE, 2014 Second PLOW Installment - March 5, 2014
TOOLS Second PLOW Installment - March 5, 2014
Since the beginning of 2011 … 20+ academic licenses 5,000 marketplace installations 8,000 applied refactorings Second PLOW Installment - March 5, 2014
State-of-the-art commercial tools Live code smell detection Smart visualizations Technical debt assessment Computer-aided refactoring Second PLOW Installment - March 5, 2014
So, tools are adopted What’s next? Management of Code Smells Second PLOW Installment - March 5, 2014
Motivation Not all code smells are equally important Why should we refactor a piece of code that neverchanges? a piece of code that is not used? a piece of code that is not involved in bugs? Second PLOW Installment - March 5, 2014
Technical debtmanagement • “Debt”is the effect of incomplete, immature, or inadequate maintenance activities • Delayed tasks may bring a short-term benefit (higher productivity, shorter release time) • Might have to be paid back in the future with “Interest” (increased effort) • “Principal” is the effort to pay off the debt Second PLOW Installment - March 5, 2014
Clone management • Tracking clones as project evolves • Verifying the consistent modification of clones • Updating clones and groups as project evolves • Assessing the harmfulness of clones Second PLOW Installment - March 5, 2014
M. Mondal, C. Roy Why don’t we use historical information to rank clones for refactoring? CSMR-WCRE 2014 Second PLOW Installment - March 5, 2014
Similarity Preserving Change Pattern If the clones co-change by preserving their similarity, they should have higher priority for refactoring Second PLOW Installment - March 5, 2014