a textual-based technique for smell detection

39
A Textual-based Technique for Smell Detection Fabio Palomba * , Annibale Panichella + , Andrea De Lucia * , Rocco Oliveto ° , Andy Zaidman + * University of Salerno, + Delft University of Technology, ° University of Molise, Italy ICPC 2016 May, 16th 2016 Austin, TX, USA

Upload: fabio-palomba

Post on 17-Feb-2017

126 views

Category:

Software


2 download

TRANSCRIPT

Page 1: A Textual-based Technique for Smell Detection

A Textual-based Technique for Smell DetectionFabio Palomba*, Annibale Panichella+, Andrea De Lucia*, Rocco Oliveto°, Andy Zaidman+

* University of Salerno, +Delft University of Technology, ° University of Molise, Italy

ICPC 2016May, 16th 2016Austin, TX, USA

Page 2: A Textual-based Technique for Smell Detection

“Bad Code Smells are symptoms of poor design or implementation choices”

[Martin Fowler]

Page 3: A Textual-based Technique for Smell Detection

[Abbes et al. - CSMR 2011]Bad Smells hinder code comprehensibility

Page 4: A Textual-based Technique for Smell Detection

[Khomh et al. - EMSE 2012]

Bad Smells increase change- and bug-proneness

Page 5: A Textual-based Technique for Smell Detection

[Banker et al. - Comm. of the ACM]Bad Smells increase maintenance costs

Page 6: A Textual-based Technique for Smell Detection

To detect code smells, several approaches and tools have

been proposed, most of them relying on structural analysis

Page 7: A Textual-based Technique for Smell Detection

N. Moha, Y.-G. Gueheneuc, L. Duchien, and A.-F. L. Meur “DECOR: A Method for the Specification and Detection of Code and Design Smells”

Transactions on Software Engineering (TSE) - Volume 36, Issue 1, 2010

Rule_Card: Long Method {Rule: Metric LOC_METHOD(Very_high, 100)

}

Page 8: A Textual-based Technique for Smell Detection

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) - Volume 41, Issue 5, May 2015

Page 9: A Textual-based Technique for Smell Detection

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) - Volume 41, Issue 5, May 2015

A class is affected by the Blob code smell when it is involved in more than 8% of the total

commits performed by developers

Page 10: A Textual-based Technique for Smell Detection

Structural and Historical Analysis are only a part of the whole story

Page 11: A Textual-based Technique for Smell Detection

/* Insert a new user in the system. * @param pUser: the user to insert.*/ public void insert(User pUser){

connect = DBConnection.getConnection();

String sql = "INSERT INTO USER" + "(login,first_name,last_name,password" + ",email,cell,id_parent) " + "VALUES (" + pUser.getLogin() + "," + pUser.getFirstName() + "," + pUser.getLastName() + "," + pUser.getPassword() + "," + pUser.getEMail() + "," + pUser.getCell() + "," + pUser.getIdParent() + ")";

executeOperation(connect, sql); }

/* Delete an user from the system. * @param pUser: the user to delete.*/ public void delete(User pUser) {

connect = DBConnection.getConnection();

String sql = "DELETE FROM USER " + "WHERE id_user = " + pUser.getId();

executeOperation(connect, sql); }

We conjecture that textual content of source code can provide useful hints for smell detection

Page 12: A Textual-based Technique for Smell Detection

public void insert(User pUser){

connect = DBConnection.getConnection();

String sql = "INSERT INTO USER" + "(login,first_name,last_name,password" + ",email,cell,id_parent) " + "VALUES (" + pUser.getLogin() + "," + pUser.getFirstName() + "," + pUser.getLastName() + "," + pUser.getPassword() + "," + pUser.getEMail() + "," + pUser.getCell() + "," + pUser.getIdParent() + ")";

String sql = "DELETE FROM USER " + "WHERE id_user = " + pUser.getId(); }

We believe that code affected by a smell contains unrelated textual content

Insert User

Delete User

Page 13: A Textual-based Technique for Smell Detection

TACO

Textual Analysis forCode smell detectiOn

Page 14: A Textual-based Technique for Smell Detection

Text Preprocessing

textual component extractor

IR normalizationprocess

StemmingTerm separation

Stop word removal…

Code ComponentCode ComponentCode Component

Smell Detector

BlobLong Method

Promiscuous PackageMisplaced Class

Feature Envy

Page 15: A Textual-based Technique for Smell Detection

Detecting Long Method instancespublic void insert(User pUser){

connect = DBConnection.getConnection();

String sql = "INSERT INTO USER" + "(login,first_name,last_name,password" + ",email,cell,id_parent) " + "VALUES (" + pUser.getLogin() + "," + pUser.getFirstName() + "," + pUser.getLastName() + "," + pUser.getPassword() + "," + pUser.getEMail() + "," + pUser.getCell() + "," + pUser.getIdParent() + ")";

String sql = "DELETE FROM USER " + "WHERE id_user = " + pUser.getId();

X. Whang, L. Pollock, K. Shanker“Automatic Segmentation of Method Code Into Meaningful Blocks: Design and Evaluation”

JSEP 2013

Page 16: A Textual-based Technique for Smell Detection

Detecting Long Method instancespublic void insert(User pUser){

connect = DBConnection.getConnection();

String sql = "INSERT INTO USER" + "(login,first_name,last_name,password" + ",email,cell,id_parent) " + "VALUES (" + pUser.getLogin() + "," + pUser.getFirstName() + "," + pUser.getLastName() + "," + pUser.getPassword() + "," + pUser.getEMail() + "," + pUser.getCell() + "," + pUser.getIdParent() + ")";

String sql = "DELETE FROM USER " + "WHERE id_user = " + pUser.getId();

X. Whang, L. Pollock, K. Shanker“Automatic Segmentation of Method Code Into Meaningful Blocks: Design and Evaluation”

JSEP 2013

Page 17: A Textual-based Technique for Smell Detection

Detecting Long Method instancespublic void insert(User pUser){

connect = DBConnection.getConnection();

String sql = "INSERT INTO USER" + "(login,first_name,last_name,password" + ",email,cell,id_parent) " + "VALUES (" + pUser.getLogin() + "," + pUser.getFirstName() + "," + pUser.getLastName() + "," + pUser.getPassword() + "," + pUser.getEMail() + "," + pUser.getCell() + "," + pUser.getIdParent() + ")";

String sql = "DELETE FROM USER " + "WHERE id_user = " + pUser.getId();

X. Whang, L. Pollock, K. Shanker“Automatic Segmentation of Method Code Into Meaningful Blocks: Design and Evaluation”

JSEP 2013

Method CohesionComputation

Page 18: A Textual-based Technique for Smell Detection

Detecting Long Method instancespublic void insert(User pUser){

connect = DBConnection.getConnection();

String sql = "INSERT INTO USER" + "(login,first_name,last_name,password" + ",email,cell,id_parent) " + "VALUES (" + pUser.getLogin() + "," + pUser.getFirstName() + "," + pUser.getLastName() + "," + pUser.getPassword() + "," + pUser.getEMail() + "," + pUser.getCell() + "," + pUser.getIdParent() + ")";

String sql = "DELETE FROM USER " + "WHERE id_user = " + pUser.getId(); }

X. Whang, L. Pollock, K. Shanker“Automatic Segmentation of Method Code Into Meaningful Blocks: Design and Evaluation”

JSEP 2013

Method CohesionComputation

Long Method Probability Computation

Page 19: A Textual-based Technique for Smell Detection

Detecting Feature Envy instances

Page 20: A Textual-based Technique for Smell Detection

Detecting Feature Envy instances

C3

method1()method2()

…methodN()

Cclosest

C5C2

C1

C4

Extracting the class Cclosest having the highest textual similarity with Mi

C6

Page 21: A Textual-based Technique for Smell Detection

Detecting Feature Envy instances

method1()method2()

…methodN()

Cclosest

Feature Envy Probability Computation

method1()method2()

…methodN()

CO

Page 22: A Textual-based Technique for Smell Detection

Empirical Study

Page 23: A Textual-based Technique for Smell Detection

TACO - Evaluating its performance

10 software systems

Page 24: A Textual-based Technique for Smell Detection

TACO - Evaluating its performance

10 software systems

Oracle available from Landfill

F. Palomba, D. Di Nucci, M.Tufano, G. Bavota, R. Oliveto, D. Poshyvanyk, A. De Lucia“Landfill: an Open Dataset of Code Smells with Public Evaluation”

MSR 2015

Page 25: A Textual-based Technique for Smell Detection

TACO - Evaluating its performance

10 software systems

PrecisionRecall

F-Measure

Oracle available from Landfill

Page 26: A Textual-based Technique for Smell Detection

10 software systems

TACO - Evaluating its performance

PrecisionRecall

F-Measure

Oracle available from Landfill

Overlap Metrics

TACO

Alternative Structural Technique

TACO && Alternative

Structural Technique

Page 27: A Textual-based Technique for Smell Detection

10 software systems

TACO - Evaluating its performance

PrecisionRecall

F-Measure

Oracle available from Landfill

Feature Envy: TACO vs JDeodorant [Tsantalis et al., TSE 2009]

Blob: TACO vs DECOR [Moha et al., TSE 2010]

Long Method: TACO vs DECOR [Moha et al., TSE 2010]

Promiscuous Package : TACO vs Clustering approach [Girvan et al., NAS 2002]

Misplaced Class: TACO vs AST-based approach [Atkinson et al., APSEC 2005]Overlap

Metrics

Page 28: A Textual-based Technique for Smell Detection

TACO - Overall F-Measure

TACOAlternative Structural Technique

Page 29: A Textual-based Technique for Smell Detection

+22%on average in terms of F-Measure

TACO - Overall F-Measure

Page 30: A Textual-based Technique for Smell Detection

TACO - A practical example Method: findTypesAndPackages()

Goal: Discover the classes and the packages of a given project

Class: CompletionEngine - Eclipse Core

Page 31: A Textual-based Technique for Smell Detection

Method: findTypesAndPackages()

Goal: Discover the classes and the packages of a given project

Class: CompletionEngine - Eclipse Core

65lines of code

TACO - A practical example

Page 32: A Textual-based Technique for Smell Detection

Method: findTypesAndPackages()

Goal: Discover the classes and the packages of a given project

Class: CompletionEngine - Eclipse Core

65lines of code

A Structural Approach cannot detect the smell!

TACO - A practical example

Page 33: A Textual-based Technique for Smell Detection

Method: findTypesAndPackages()

Goal: Discover the classes and the packages of a given project

Class: CompletionEngine - Eclipse Core

65lines of code

A Structural Approach cannot detect the smell!

TACO, instead, is able to detect a Long Method instance

TACO - A practical example

Page 34: A Textual-based Technique for Smell Detection

TACO - Evaluating the complementarity with structural approaches

TACOAlternative Structural TechniqueOverlap

Page 35: A Textual-based Technique for Smell Detection

Textual and Structural Information

are Highly Complementary

Page 36: A Textual-based Technique for Smell Detection

What about a combined technique for smell detection?

Page 37: A Textual-based Technique for Smell Detection

Do developers perceive textual smells as actual design flaws?

Page 38: A Textual-based Technique for Smell Detection

Is TACO able to detect other code smells?

Page 39: A Textual-based Technique for Smell Detection

A Textual-based Technique for Smell DetectionFabio Palomba*, Annibale Panichella+, Andrea De Lucia*, Rocco Oliveto°, Andy Zaidman+

* University of Salerno, +Delft University of Technology, ° University of Molise, Italy

ICPC 2016May, 16th 2016Austin, TX, USA