Detecting and Removing Bad Code 
Smells from Source Code 
A review of my first PhD year 
Fabio Palomba 
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 
Low Internal Quality 
Documentation Debt 
Coding Style Violation 
Code Smell 
Test debt 
Architectural Debt Structural Debt 
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
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 
Historical Information 
for Smell deTection 
method 
getUser 
has been 
added
HISTChange History Extractor 
log download code analyzer 
Historical Information 
for Smell deTection 
method 
getUser 
has been 
added 
method 
getData 
has been 
modified
HISTChange History Extractor 
log download code analyzer 
Historical Information 
for Smell deTection 
method 
getUser 
has been 
added 
method 
getData 
has been 
modified 
method 
getLogin 
has been 
moved
HISTChange History Extractor 
log download code analyzer 
Historical Information 
for Smell deTection 
method 
getUser 
has been 
added 
method 
getData 
has been 
modified 
method 
getLogin 
has been 
moved 
class 
User 
has been 
added
HISTChange History Extractor 
log download code analyzer 
Historical Information 
for Smell deTection 
method 
getUser 
has been 
added 
method 
getData 
has been 
modified 
method 
getLogin 
has been 
moved 
class 
User 
has been 
added 
... 
... 
... 
...
HISTChange History Extractor 
log download code analyzer 
Code Smells Detector 
Historical Information 
for Smell deTection 
method 
getUser 
has been 
added 
method 
getData 
has been 
modified 
method 
getLogin 
has been 
moved 
class 
User 
has been 
added 
... 
... 
... 
...
HISTChange History Extractor 
log download code analyzer 
Code Smells Detector 
Historical Information 
for Smell deTection 
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
HISTChange History Extractor 
log download code analyzer 
Code Smells Detector 
Historical Information 
for Smell deTection 
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
HISTCode Smell Detector 
Five different smells considered 
Divergent Change 
Shotugun Surgery 
Parallel Inheritance 
Historical Information 
for Smell deTection
HISTCode Smell Detector 
Five different smells considered 
Three code smells, by definition, 
to consider as “historical” smells 
Divergent Change 
Shotugun Surgery 
Parallel Inheritance 
Historical Information 
for Smell deTection
HISTCode Smell Detector 
Five different smells considered 
Three code smells, by definition, 
to consider as “historical” smells 
Divergent Change 
Shotugun Surgery 
Parallel Inheritance 
Blob 
Feature Envy 
Historical Information 
for Smell deTection
HISTCode Smell Detector 
Five different smells considered 
Three code smells, by definition, 
to consider as “historical” smells 
Divergent Change 
Shotugun Surgery 
Parallel Inheritance 
Two code smells generally 
detected by structural analysis, 
where the historical analysis can 
aid in the identification of 
complementary information 
Blob 
Feature Envy 
Historical Information 
for Smell deTection
Code Smells Detector 
divergent change
Code Smells Detector 
divergent change 
A class is changed in different 
ways for different reasons
Code Smells Detector 
divergent change 
A class is changed in different 
ways for different reasons 
Solution: 
Extract Class Refactoring
Code Smells Detector 
divergent change 
A class is changed in different 
ways for different reasons 
Solution: 
Extract Class Refactoring 
Detection 
Classes 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 Detector 
blob
Code Smells Detector 
blob 
A class implementing several 
responsibilities, having a large size, 
and dependencies with data classes
Code Smells Detector 
blob 
A class implementing several 
responsibilities, having a large size, 
and dependencies with data classes 
Solution: 
Extract Class refactoring
Code Smells Detector 
blob 
A class implementing several 
responsibilities, having a large size, 
and dependencies with data classes 
Solution: 
Extract Class refactoring 
Detection 
Blobs are identified as classes frequently modified in 
commits involving at least another class. 
t1 t2 t3 t4 t5 t6 t7 t8 t9
Evaluation 
detection accuracy
Evaluation 
detection accuracy 
20 open source 
systems
Evaluation 
detection accuracy 
Comparing HIST with static code 
analysis technique on a manually 
built oracle 
20 open source 
systems
Evaluation 
detection accuracy 
20 open source 
systems 
Shotgun Surgery 
Parallel Inheritance 
Divergent Change 
Blob 
Feature Envy 
Comparing HIST with static code 
analysis technique on a manually 
built oracle 
HIST F-Measure CA technique F-Measure 
92% 
71% 
82% 
64% 
77% 
0% 
9% 
11% 
48% 
68%
Evaluation 
detection accuracy 
Comparing HIST with static code 
analysis technique on a manually 
built oracle 
HIST and 
the CA techniques 
20 open source 
systems 
are highly complementary
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
http://www.sesa.unisa.it/landfill 
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)
HIST 
Mar 
16 The tool is coming soon... 
Historical Information 
for Smell deTection
Do They Really Smell Bad? 
A Study on Developers’ Perception of 
Bad Code Smells 
Fabio Palomba, Gabriele Bavota, Massimiliano Di Penta, 
Rocco Oliveto, Andrea De Lucia 
ICSME 2014 
Victoria - Canada 
October 1st, 2014
“We don’t see things as they are, 
we see things as we are” 
Anais Nin
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? 
Investigating the 
developers’ point of view
Smells generally not Perceived as 
Design or Implementation Problems 
THEORical 
problems
Smells generally Perceived and 
Identified by Respondents 
THEY SHOULD BE 
CAREFULLY ANALYZED
Smells whose Perception may Var y 
dependently by Their Intensit y 
THEY SHOULD BE 
studied more
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.”
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 metrics 
11 bad smells 
Studying if quality metrics 
/ bad smells capture 
refactoring operations
3 open source 
systems 
11 quality metrics 
11 bad smells 
12,922 refactoring operations 
manually validated 
Studying if quality metrics 
/ bad smells capture 
refactoring operations
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)
http://www.sesa.unisa.it/tools/aries.jsp 
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)
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 
Low Internal Quality 
Documentation Debt 
Coding Style Violation 
Code Smell 
Test debt 
Architectural Debt Structural Debt 
Code Complexity
Fabio Palomba 
fpalomba.unisa.it 
dibt.unimol.it/fpalomba 
Research is 
a work of

PhD Symposium 2014

  • 1.
    Detecting and RemovingBad Code Smells from Source Code A review of my first PhD year Fabio Palomba PhD Symposium 2014
  • 6.
    Technical Debt is... “Not quite right code which we postpone making it right.” W. Cunningham
  • 7.
    Technical Debt is... “Not quite right code which we postpone making it right.” W. Cunningham Low Internal Quality Documentation Debt Coding Style Violation Code Smell Test debt Architectural Debt Structural Debt Code Complexity
  • 8.
  • 10.
    [Abbes et al.CSMR 2011]
  • 11.
    [Abbes et al.CSMR 2011] Bad Smells hinder code comprehensibility
  • 12.
    [Khomh et al.EMSE 2012]
  • 13.
    [Khomh et al.EMSE 2012] Bad Smells increase change and fault proneness
  • 14.
    [Banker et al.Comm. of the ACM 1993]
  • 15.
    [Banker et al.Comm. of the ACM 1993] Bad smells increase maintenance costs
  • 16.
    F. Palomba, A.De Lucia, G. Bavota, R. Oliveto. “Anti-Pattern Detection: Methods, Challanges, and Open Issues” Advances in Computers, vol. 95 (to appear)
  • 17.
    Many detection techniques use structural analysis
  • 18.
    Many bad smellsare intrinsically characterized by how code elements change over time, rather than by structural properties
  • 19.
    HIST Historical Information for Smell deTection
  • 20.
    HIST Historical Information for Smell deTection
  • 21.
    HISTChange History Extractor Historical Information for Smell deTection
  • 22.
    HISTChange History Extractor log download Historical Information for Smell deTection
  • 23.
    HISTChange History Extractor log download code analyzer Historical Information for Smell deTection
  • 24.
    HISTChange History Extractor log download code analyzer Historical Information for Smell deTection method getUser has been added
  • 25.
    HISTChange History Extractor log download code analyzer Historical Information for Smell deTection method getUser has been added method getData has been modified
  • 26.
    HISTChange History Extractor log download code analyzer Historical Information for Smell deTection method getUser has been added method getData has been modified method getLogin has been moved
  • 27.
    HISTChange History Extractor log download code analyzer Historical Information for Smell deTection method getUser has been added method getData has been modified method getLogin has been moved class User has been added
  • 28.
    HISTChange History Extractor log download code analyzer Historical Information for Smell deTection method getUser has been added method getData has been modified method getLogin has been moved class User has been added ... ... ... ...
  • 29.
    HISTChange History Extractor log download code analyzer Code Smells Detector Historical Information for Smell deTection method getUser has been added method getData has been modified method getLogin has been moved class User has been added ... ... ... ...
  • 30.
    HISTChange History Extractor log download code analyzer Code Smells Detector Historical Information for Smell deTection 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
  • 31.
    HISTChange History Extractor log download code analyzer Code Smells Detector Historical Information for Smell deTection 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
  • 32.
    HISTCode Smell Detector Five different smells considered Divergent Change Shotugun Surgery Parallel Inheritance Historical Information for Smell deTection
  • 33.
    HISTCode Smell Detector Five different smells considered Three code smells, by definition, to consider as “historical” smells Divergent Change Shotugun Surgery Parallel Inheritance Historical Information for Smell deTection
  • 34.
    HISTCode Smell Detector Five different smells considered Three code smells, by definition, to consider as “historical” smells Divergent Change Shotugun Surgery Parallel Inheritance Blob Feature Envy Historical Information for Smell deTection
  • 35.
    HISTCode Smell Detector Five different smells considered Three code smells, by definition, to consider as “historical” smells Divergent Change Shotugun Surgery Parallel Inheritance Two code smells generally detected by structural analysis, where the historical analysis can aid in the identification of complementary information Blob Feature Envy Historical Information for Smell deTection
  • 36.
    Code Smells Detector divergent change
  • 37.
    Code Smells Detector divergent change A class is changed in different ways for different reasons
  • 38.
    Code Smells Detector divergent change A class is changed in different ways for different reasons Solution: Extract Class Refactoring
  • 39.
    Code Smells Detector divergent change A class is changed in different ways for different reasons Solution: Extract Class Refactoring Detection Classes 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
  • 40.
  • 41.
    Code Smells Detector blob A class implementing several responsibilities, having a large size, and dependencies with data classes
  • 42.
    Code Smells Detector blob A class implementing several responsibilities, having a large size, and dependencies with data classes Solution: Extract Class refactoring
  • 43.
    Code Smells Detector blob A class implementing several responsibilities, having a large size, and dependencies with data classes Solution: Extract Class refactoring Detection Blobs are identified as classes frequently modified in commits involving at least another class. t1 t2 t3 t4 t5 t6 t7 t8 t9
  • 44.
  • 45.
    Evaluation detection accuracy 20 open source systems
  • 46.
    Evaluation detection accuracy Comparing HIST with static code analysis technique on a manually built oracle 20 open source systems
  • 47.
    Evaluation detection accuracy 20 open source systems Shotgun Surgery Parallel Inheritance Divergent Change Blob Feature Envy Comparing HIST with static code analysis technique on a manually built oracle HIST F-Measure CA technique F-Measure 92% 71% 82% 64% 77% 0% 9% 11% 48% 68%
  • 48.
    Evaluation detection accuracy Comparing HIST with static code analysis technique on a manually built oracle HIST and the CA techniques 20 open source systems are highly complementary
  • 49.
    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)
  • 50.
    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)
  • 51.
    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
  • 52.
    http://www.sesa.unisa.it/landfill 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)
  • 53.
    HIST Mar 16The tool is coming soon... Historical Information for Smell deTection
  • 54.
    Do They ReallySmell Bad? A Study on Developers’ Perception of Bad Code Smells Fabio Palomba, Gabriele Bavota, Massimiliano Di Penta, Rocco Oliveto, Andrea De Lucia ICSME 2014 Victoria - Canada October 1st, 2014
  • 55.
    “We don’t seethings as they are, we see things as we are” Anais Nin
  • 56.
  • 57.
    RQ1: To whatextent do bad smells reflect developers‘ perception of design problems? Investigating the developers’ point of view
  • 58.
    RQ1: To whatextent do bad smells reflect developers‘ perception of design problems? RQ2: What are the bad smells that developers feel as the most harmful? Investigating the developers’ point of view
  • 59.
    Smells generally notPerceived as Design or Implementation Problems THEORical problems
  • 60.
    Smells generally Perceivedand Identified by Respondents THEY SHOULD BE CAREFULLY ANALYZED
  • 61.
    Smells whose Perceptionmay Var y dependently by Their Intensit y THEY SHOULD BE studied more
  • 62.
    On the InnateRelationship between Quality and Refactoring
  • 63.
    Refactoring is... “Refactoringis a disciplined technique for restructuring an existing body of code, improving its non-functional attributes without changing its external behavior.”
  • 64.
    3 open source systems Studying if quality metrics / bad smells capture refactoring operations
  • 65.
    3 open source systems 11 quality metrics Studying if quality metrics / bad smells capture refactoring operations
  • 66.
    3 open source systems 11 quality metrics 11 bad smells Studying if quality metrics / bad smells capture refactoring operations
  • 67.
    3 open source systems 11 quality metrics 11 bad smells 12,922 refactoring operations manually validated Studying if quality metrics / bad smells capture refactoring operations
  • 68.
    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)
  • 69.
    http://www.sesa.unisa.it/tools/aries.jsp 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)
  • 70.
  • 71.
    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)
  • 72.
    F. Palomba “TextualAnalysis for Code Smell Detection” Submitted to the International Conference on Software Engineering (ICSE 2015)
  • 73.
    Learning from thepast for prioritizing bad code smells
  • 74.
    Technical Debt is... “Not quite right code which we postpone making it right.” W. Cunningham Low Internal Quality Documentation Debt Coding Style Violation Code Smell Test debt Architectural Debt Structural Debt Code Complexity
  • 75.
    Fabio Palomba fpalomba.unisa.it dibt.unimol.it/fpalomba Research is a work of