phd symposium 2014

75
Detecting and Removing Bad Code Smells from Source Code Fabio Palomba A review of my first PhD year PhD Symposium 2014

Upload: fabio-palomba

Post on 10-Jul-2015

198 views

Category:

Software


0 download

TRANSCRIPT

Page 1: PhD Symposium 2014

Detecting and Removing Bad Code Smells from Source Code

Fabio Palomba

A review of my first PhD year

PhD Symposium 2014

Page 2: PhD Symposium 2014
Page 3: PhD Symposium 2014
Page 4: PhD Symposium 2014
Page 5: PhD Symposium 2014
Page 6: PhD Symposium 2014

Technical Debt is...“Not quite right code which we

postpone making it right.”

W. Cunningham

Page 7: PhD Symposium 2014

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

Page 8: PhD Symposium 2014

Bad Code Smells

Page 9: PhD Symposium 2014
Page 10: PhD Symposium 2014

[Abbes et al. CSMR 2011]

Page 11: PhD Symposium 2014

[Abbes et al. CSMR 2011]

Bad Smells hinder code comprehensibility

Page 12: PhD Symposium 2014

[Khomh et al. EMSE 2012]

Page 13: PhD Symposium 2014

[Khomh et al. EMSE 2012]

Bad Smells increase change and fault proneness

Page 14: PhD Symposium 2014

[Banker et al. Comm. of the ACM 1993]

Page 15: PhD Symposium 2014

[Banker et al. Comm. of the ACM 1993]

Bad smells increase maintenance costs

Page 16: PhD Symposium 2014

F. Palomba, A. De Lucia, G. Bavota, R. Oliveto. “Anti-Pattern Detection: Methods, Challanges, and Open Issues”

Advances in Computers, vol. 95 (to appear)

Page 17: PhD Symposium 2014

Many detection techniques use structural analysis

Page 18: PhD Symposium 2014

Many bad smells are intrinsically characterized by how code elements change over time, rather

than by structural properties

Page 19: PhD Symposium 2014

HIST

Historical Information for Smell deTection

Page 20: PhD Symposium 2014

Historical Information for Smell deTection

HIST

Page 21: PhD Symposium 2014

Historical Information for Smell deTection

HISTChange History Extractor

Page 22: PhD Symposium 2014

Historical Information for Smell deTection

HISTChange History Extractor

log download

Page 23: PhD Symposium 2014

Historical Information for Smell deTection

HISTChange History Extractor

log download code analyzer

Page 24: PhD Symposium 2014

Historical Information for Smell deTection

HISTChange History Extractor

log download code analyzer

method getUser has been

added

Page 25: PhD Symposium 2014

Historical Information for Smell deTection

HISTChange History Extractor

log download code analyzer

method getUser has been

added

method getData has been modified

Page 26: PhD Symposium 2014

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

Page 27: PhD Symposium 2014

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

Page 28: PhD Symposium 2014

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

...

...

...

...

Page 29: PhD Symposium 2014

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

...

...

...

...

Page 30: PhD Symposium 2014

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

Page 31: PhD Symposium 2014

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

Page 32: PhD Symposium 2014

Historical Information for Smell deTection

HISTCode Smell DetectorFive different smells considered

Divergent ChangeShotugun SurgeryParallel Inheritance

Page 33: PhD Symposium 2014

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

Page 34: PhD Symposium 2014

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

Page 35: PhD Symposium 2014

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

Page 36: PhD Symposium 2014

Code Smells Detectordivergent change

Page 37: PhD Symposium 2014

Code Smells Detectordivergent change

A class is changed in different ways for different reasons

Page 38: PhD Symposium 2014

Code Smells Detectordivergent change

A class is changed in different ways for different reasons

Solution: Extract Class Refactoring

Page 39: PhD Symposium 2014

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

Page 40: PhD Symposium 2014

Code Smells Detectorblob

Page 41: PhD Symposium 2014

Code Smells Detectorblob

A class implementing several responsibilities, having a large size, and dependencies with data classes

Page 42: PhD Symposium 2014

Code Smells Detectorblob

A class implementing several responsibilities, having a large size, and dependencies with data classes

Solution: Extract Class refactoring

Page 43: PhD Symposium 2014

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

Page 44: PhD Symposium 2014

Evaluationdetection accuracy

Page 45: PhD Symposium 2014

Evaluationdetection accuracy

20 open source systems

Page 46: PhD Symposium 2014

Evaluationdetection accuracy

Comparing HIST with static code analysis technique on a manually

built oracle20 open source

systems

Page 47: PhD Symposium 2014

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

Page 48: PhD Symposium 2014

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

Page 49: PhD Symposium 2014

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)

Page 50: PhD Symposium 2014

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)

Page 51: PhD Symposium 2014

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

Page 52: PhD Symposium 2014

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

Page 53: PhD Symposium 2014

HIST

Historical Information for Smell deTection

Mar

16 The tool is coming soon...

Page 54: PhD Symposium 2014

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

Page 55: PhD Symposium 2014

“We don’t see things as they are, we see things as we are” Anais Nin

Page 56: PhD Symposium 2014

Investigating the developers’ point of view

Page 57: PhD Symposium 2014

Investigating the developers’ point of view

RQ1: To what extent do bad smells reflect developers‘

perception of design problems?

Page 58: PhD Symposium 2014

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?

Page 59: PhD Symposium 2014

Smells generally not Perceived as Design or Implementation Problems

THEORical

problems

Page 60: PhD Symposium 2014

Smells generally Perceived and Identified by Respondents

THEY SHOULD BE

CAREFULLY ANALYZED

Page 61: PhD Symposium 2014

THEY SHOULD BE

studied more

Smells whose Perception may Vary dependently by Their Intensity

Page 62: PhD Symposium 2014

On the Innate Relationship between Quality and Refactoring

Page 63: PhD Symposium 2014

Refactoring is...“Refactoring is a disciplined technique for restructuring an

existing body of code, improving its non-functional attributes without changing its external behavior.”

Page 64: PhD Symposium 2014

Studying if quality metrics / bad smells capture

refactoring operations

3 open source systems

Page 65: PhD Symposium 2014

Studying if quality metrics / bad smells capture

refactoring operations

3 open source systems

11 quality metrics

Page 66: PhD Symposium 2014

Studying if quality metrics / bad smells capture

refactoring operations

3 open source systems

11 quality metrics11 bad smells

Page 67: PhD Symposium 2014

Studying if quality metrics / bad smells capture

refactoring operations

3 open source systems

11 quality metrics11 bad smells

12,922 refactoring operations manually validated

Page 68: PhD Symposium 2014

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)

Page 69: PhD Symposium 2014

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

Page 70: PhD Symposium 2014

Moving Forward

Page 71: PhD Symposium 2014

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)

Page 72: PhD Symposium 2014

F. Palomba“Textual Analysis for Code Smell Detection”

Submitted to the International Conference on Software Engineering (ICSE 2015)

Page 73: PhD Symposium 2014

Learning from the past for prioritizing bad code smells

Page 74: PhD Symposium 2014

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

Page 75: PhD Symposium 2014

Fabio Palombafpalomba.unisa.itdibt.unimol.it/fpalomba

Research is a work of