phd symposium 2014
TRANSCRIPT
Detecting and Removing Bad Code Smells from Source Code
Fabio Palomba
A review of my first PhD year
PhD Symposium 2014
Technical Debt is...“Not quite right code which we
postpone making it right.”
W. Cunningham
Technical Debt is...“Not quite right code which we
postpone making it right.”
W. Cunningham
Documentation DebtCode Smell
Test debt
Coding Style Violation
Structural DebtArchitectural Debt
Low Internal Quality
Code Complexity
Bad Code Smells
[Abbes et al. CSMR 2011]
[Abbes et al. CSMR 2011]
Bad Smells hinder code comprehensibility
[Khomh et al. EMSE 2012]
[Khomh et al. EMSE 2012]
Bad Smells increase change and fault proneness
[Banker et al. Comm. of the ACM 1993]
[Banker et al. Comm. of the ACM 1993]
Bad smells increase maintenance costs
F. Palomba, A. De Lucia, G. Bavota, R. Oliveto. “Anti-Pattern Detection: Methods, Challanges, and Open Issues”
Advances in Computers, vol. 95 (to appear)
Many detection techniques use structural analysis
Many bad smells are intrinsically characterized by how code elements change over time, rather
than by structural properties
HIST
Historical Information for Smell deTection
Historical Information for Smell deTection
HIST
Historical Information for Smell deTection
HISTChange History Extractor
Historical Information for Smell deTection
HISTChange History Extractor
log download
Historical Information for Smell deTection
HISTChange History Extractor
log download code analyzer
Historical Information for Smell deTection
HISTChange History Extractor
log download code analyzer
method getUser has been
added
Historical Information for Smell deTection
HISTChange History Extractor
log download code analyzer
method getUser has been
added
method getData has been modified
Historical Information for Smell deTection
HISTChange History Extractor
log download code analyzer
method getUser has been
added
method getData has been modified
method getLogin has been moved
Historical Information for Smell deTection
HISTChange History Extractor
log download code analyzer
method getUser has been
added
method getData has been modified
method getLogin has been moved
class User
has been added
Historical Information for Smell deTection
HISTChange History Extractor
log download code analyzer
method getUser has been
added
method getData has been modified
method getLogin has been moved
class User
has been added
...
...
...
...
Historical Information for Smell deTection
HISTChange History Extractor
Code Smells Detector
log download code analyzer
method getUser has been
added
method getData has been modified
method getLogin has been moved
class User
has been added
...
...
...
...
Historical Information for Smell deTection
HISTChange History Extractor
Code Smells Detector
log download code analyzer
method getUser has been
added
method getData has been modified
method getLogin has been moved
class User
has been added
...
...
...
...
Association rule discovery to capture co-changes between entities
Historical Information for Smell deTection
HISTChange History Extractor
Code Smells Detector
log download code analyzer
method getUser has been
added
method getData has been modified
method getLogin has been moved
class User
has been added
...
...
...
...
Association rule discovery to capture co-changes between entities
Analysis of change frequency of some specific entities
Historical Information for Smell deTection
HISTCode Smell DetectorFive different smells considered
Divergent ChangeShotugun SurgeryParallel Inheritance
Historical Information for Smell deTection
HISTCode Smell DetectorFive different smells considered
Three code smells, by definition, to consider as “historical” smells
Divergent ChangeShotugun SurgeryParallel Inheritance
Historical Information for Smell deTection
HISTCode Smell DetectorFive different smells considered
Three code smells, by definition, to consider as “historical” smells
Divergent ChangeShotugun SurgeryParallel Inheritance
BlobFeature Envy
Historical Information for Smell deTection
HISTCode Smell DetectorFive different smells considered
Three code smells, by definition, to consider as “historical” smells
Two code smells generally detected by structural analysis, where the historical analysis can aid in the identification of complementary information
Divergent ChangeShotugun SurgeryParallel Inheritance
BlobFeature Envy
Code Smells Detectordivergent change
Code Smells Detectordivergent change
A class is changed in different ways for different reasons
Code Smells Detectordivergent change
A class is changed in different ways for different reasons
Solution: Extract Class Refactoring
Code Smells Detectordivergent change
A class is changed in different ways for different reasons
Solution: Extract Class Refactoring
DetectionClasses containing at least two sets of methods such that:
(i) all methods in the set change together as detected by the association rules
(ii) each method in the set does not change with methods in other sets
Code Smells Detectorblob
Code Smells Detectorblob
A class implementing several responsibilities, having a large size, and dependencies with data classes
Code Smells Detectorblob
A class implementing several responsibilities, having a large size, and dependencies with data classes
Solution: Extract Class refactoring
Code Smells Detectorblob
A class implementing several responsibilities, having a large size, and dependencies with data classes
Solution: Extract Class refactoring
DetectionBlobs are identified as classes frequently modified in commits involving at least another class.
t1 t3t2 t4 t6t5 t7 t9t8
Evaluationdetection accuracy
Evaluationdetection accuracy
20 open source systems
Evaluationdetection accuracy
Comparing HIST with static code analysis technique on a manually
built oracle20 open source
systems
Evaluationdetection accuracy
20 open source systems
Shotgun Surgery
Parallel Inheritance
Divergent Change
Blob
Feature Envy
HIST F-Measure CA technique F-Measure92%
71%
82%
64%
77%
0%
9%
11%
48%
68%
Comparing HIST with static code analysis technique on a manually
built oracle
Evaluationdetection accuracy
HIST and the CA techniques
are highly complementary
20 open source systems
Comparing HIST with static code analysis technique on a manually
built oracle
F. Palomba, G. Bavota, M. Di Penta, R. Oliveto, A. De Lucia, and D. Poshyvanyk. “Detecting Bad Smells in Source Code using Change History Information” - Distinguished Paper Award
International Conference on Automated Software Engineering (ASE 2013)
F. Palomba, G. Bavota, M. Di Penta, R. Oliveto, A. De Lucia, and D. Poshyvanyk. “Detecting Bad Smells in Source Code using Change History Information” - Distinguished Paper Award
International Conference on Automated Software Engineering (ASE 2013)
F. Palomba, G. Bavota, M. Di Penta, R. Oliveto, D. Poshyvanyk and A. De Lucia. “Mining Version Histories for Detecting Code Smells”
Transactions on Software Engineering (TSE) - 2015
F. Palomba, D. Di Nucci, M. Tufano, G. Bavota, M. Di Penta, R. Oliveto, D. Poshyvanyk and A. De Lucia. “Landfill: an Open Dataset of Code Smells with Public Evaluation”
Submitted to the International Conference on Software Engineering (ICSE 2015)
http://www.sesa.unisa.it/landfill
HIST
Historical Information for Smell deTection
Mar
16 The tool is coming soon...
Do They Really Smell Bad? A Study on Developers’ Perception of Bad Code SmellsFabio Palomba, Gabriele Bavota, Massimiliano Di Penta, Rocco Oliveto, Andrea De Lucia
ICSME 2014Victoria - CanadaOctober 1st, 2014
“We don’t see things as they are, we see things as we are” Anais Nin
Investigating the developers’ point of view
Investigating the developers’ point of view
RQ1: To what extent do bad smells reflect developers‘
perception of design problems?
Investigating the developers’ point of view
RQ1: To what extent do bad smells reflect developers‘
perception of design problems?
RQ2: What are the bad smells that developers feel
as the most harmful?
Smells generally not Perceived as Design or Implementation Problems
THEORical
problems
Smells generally Perceived and Identified by Respondents
THEY SHOULD BE
CAREFULLY ANALYZED
THEY SHOULD BE
studied more
Smells whose Perception may Vary dependently by Their Intensity
On the Innate Relationship between Quality and Refactoring
Refactoring is...“Refactoring is a disciplined technique for restructuring an
existing body of code, improving its non-functional attributes without changing its external behavior.”
Studying if quality metrics / bad smells capture
refactoring operations
3 open source systems
Studying if quality metrics / bad smells capture
refactoring operations
3 open source systems
11 quality metrics
Studying if quality metrics / bad smells capture
refactoring operations
3 open source systems
11 quality metrics11 bad smells
Studying if quality metrics / bad smells capture
refactoring operations
3 open source systems
11 quality metrics11 bad smells
12,922 refactoring operations manually validated
G. Bavota, A. De Lucia, M. Di Penta, R. Oliveto and F. Palomba. “An Experimental Investigation on the Innate Relationship between Quality and Refactoring”
Submitted to Transactions on Software Engineering and Methodology (TOSEM)
F. Palomba, M. Tufano, G. Bavota, R. Oliveto, A. Marcus, D. Poshyvanyk, and A. De Lucia. “Extract Package Refactoring in ARIES”
Submitted to the International Conference on Software Engineering (ICSE 2015)
http://www.sesa.unisa.it/tools/aries.jsp
Moving Forward
M. Tufano, F. Palomba, G. Bavota, R. Oliveto, M. Di Penta, A. De Lucia, and D. Poshyvanyk“When and Why Your Code Starts to Smell Bad”
Submitted to the International Conference on Software Engineering (ICSE 2015)
F. Palomba“Textual Analysis for Code Smell Detection”
Submitted to the International Conference on Software Engineering (ICSE 2015)
Learning from the past for prioritizing bad code smells
Technical Debt is...“Not quite right code which we
postpone making it right.”
W. Cunningham
Documentation DebtCode Smell
Test debt
Coding Style Violation
Structural DebtArchitectural Debt
Low Internal Quality
Code Complexity
Fabio Palombafpalomba.unisa.itdibt.unimol.it/fpalomba
Research is a work of