detecting bad smells in source code using change history information

24
Detecting Bad Smells in Source Code Using Change History Information Pós Graduação em Ciência da Computação Aluno : Carlos Eduardo Dantas Orientador : Marcelo Maia Fábio Polomba Gabriele Bavota Automated Software Engineering (ASE) Massimiliano Di Penta 11 - 15 / nov / 2013 Andrea de Lucia

Upload: carlos-eduardo-dantas

Post on 16-Jul-2015

74 views

Category:

Software


5 download

TRANSCRIPT

Page 1: Detecting bad smells in source code using change history information

Detecting Bad Smells in Source Code Using Change

History Information

Pós Graduação em Ciência da ComputaçãoAluno: Carlos Eduardo DantasOrientador: Marcelo Maia

Fábio PolombaGabriele Bavota Automated Software Engineering (ASE)Massimiliano Di Penta 11-15/nov/2013Andrea de Lucia

Page 2: Detecting bad smells in source code using change history information

Detecting Bad Smells in Source Code Using Change History Information

Introduction

• Bad Smells is a symptom of poor design and implementation choices, and makesource code more difficult to maintain;

• Low quality is generally associated withlower productivity, more rework andmore effort for developers.

Page 3: Detecting bad smells in source code using change history information

Detecting Bad Smells in Source Code Using Change History Information

Introduction

• Bad Smells need to be carefully detectedand monitored;

• Refactoring actions should be planned andperformed to deal with them.

Page 4: Detecting bad smells in source code using change history information

Detecting Bad Smells in Source Code Using Change History Information

Introduction

• Approaches to detect bad smells in source code, rely on structural information extracted from source code;

• Ex: DECOR, Jdeodorant,ComplexClass;

• Can´t detect many of the smells described by Fowler, that are intrinsically characterized by how source code changes over time

Page 5: Detecting bad smells in source code using change history information

Detecting Bad Smells in Source Code Using Change History Information

HIST (Historical Informationfor Smell deTection)

• Approach to detect source code smells based on change history information extracted from versioning systems;

• Analyzing co-changes occurring between source code artifacts;

• Detect 5 bad smells from Fowler´s catalog.

Page 6: Detecting bad smells in source code using change history information

Detecting Bad Smells in Source Code Using Change History Information

HIST - Divergent Change

• Class is change in different ways for different reasons

Page 7: Detecting bad smells in source code using change history information

Detecting Bad Smells in Source Code Using Change History Information

HIST - Shotgun Surgery

• Changes in some class triggers many littlechanges to several other classes;

• Detection – at least one method thatchanges with methods present in more than X different classes.

Page 8: Detecting bad smells in source code using change history information

Detecting Bad Smells in Source Code Using Change History Information

HIST – Parallel Inheritance

• Every time you make a subclass of oneclass, you also have to make a subclass ofanother.

Page 9: Detecting bad smells in source code using change history information

Detecting Bad Smells in Source Code Using Change History Information

HIST – Blob

• Class implementing several responsabilities, large number of atributes, operations and dependencies.

Page 10: Detecting bad smells in source code using change history information

Detecting Bad Smells in Source Code Using Change History Information

HIST – Feature Envy

• A method is more interested in a classother than the one it is actually in.

• Detection – methods affected as thoseinvolved in commits with methods ofanother class of the system Y% more thanin commits with methods of their class.

Page 11: Detecting bad smells in source code using change history information

Detecting Bad Smells in Source Code Using Change History Information

HIST (Historical Informationfor Smell deTection)

• Process – Markos European Project

Page 12: Detecting bad smells in source code using change history information

Detecting Bad Smells in Source Code Using Change History Information

Study Design

• Goal: evaluate the effectiveness of HIST;

• RQ1 – How does HIST perform in detecting code smells?

• RQ2 – How does HIST compare to the techniques based on static code analysis?

Page 13: Detecting bad smells in source code using change history information

Detecting Bad Smells in Source Code Using Change History Information

Study Design - Projects

Page 14: Detecting bad smells in source code using change history information

Detecting Bad Smells in Source Code Using Change History Information

Study Design - snapshot

• Split the Project history, running HIST onthe corresponding snapshot;

• Simulating a developer performing code smell detection on an evolving software system;

• Risk to perform code smell detection on a very unstable snapshot, or development motionless.

Page 15: Detecting bad smells in source code using change history information

Detecting Bad Smells in Source Code Using Change History Information

Study Design - Oracle

• Manually build by 2 master´s students, analysing each snapshot’s source code looking for instances of those smells;

• Students were not aware of the experimental goals and of the way that HIST identifies code smells

Page 16: Detecting bad smells in source code using change history information

Detecting Bad Smells in Source Code Using Change History Information

Study Design - metrics

• cor – set of true positive smells (manually identified);

• det – set of code smells detected by HIST.

Page 17: Detecting bad smells in source code using change history information

Detecting Bad Smells in Source Code Using Change History Information

Study Design - metrics

Page 18: Detecting bad smells in source code using change history information

Detecting Bad Smells in Source Code Using Change History Information

Results

Page 19: Detecting bad smells in source code using change history information

Detecting Bad Smells in Source Code Using Change History Information

Results

Page 20: Detecting bad smells in source code using change history information

Detecting Bad Smells in Source Code Using Change History Information

Results

Page 21: Detecting bad smells in source code using change history information

Detecting Bad Smells in Source Code Using Change History Information

Results - Summary

Page 22: Detecting bad smells in source code using change history information

Detecting Bad Smells in Source Code Using Change History Information

Threads to Validity

• Oracle manual analysis could have missed some smells, or else identified some false positives;

• Define alternative static detection techniques em 3 bad smells, that may or may not be the most suitable ones among those based solely on structural information.

Page 23: Detecting bad smells in source code using change history information

Detecting Bad Smells in Source Code Using Change History Information

Conclusion

• HIST clearly outperforms static code analysis;

• HIST highlight smells that are subject to frequent changes;

• HIST requires sufficient amount ofhistorical information to infer usefulassociation rules.

Page 24: Detecting bad smells in source code using change history information

Detecting Bad Smells in Source Code Using Change History Information

Questions and future research

• Can we define a hybrid approach to detectsmells ?

• Does a class affected by a smell representa problem even if it does not change sooften?

• Does HIST have applicability on othertypes of smells?