a textual-based technique for smell detection
TRANSCRIPT
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
“Bad Code Smells are symptoms of poor design or implementation choices”
[Martin Fowler]
[Abbes et al. - CSMR 2011]Bad Smells hinder code comprehensibility
[Khomh et al. - EMSE 2012]
Bad Smells increase change- and bug-proneness
[Banker et al. - Comm. of the ACM]Bad Smells increase maintenance costs
To detect code smells, several approaches and tools have
been proposed, most of them relying on structural analysis
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)
}
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
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
Structural and Historical Analysis are only a part of the whole story
/* 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
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
TACO
Textual Analysis forCode 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
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
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
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
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
Detecting Feature Envy instances
Detecting Feature Envy instances
C3
method1()method2()
…methodN()
Cclosest
C5C2
C1
C4
Extracting the class Cclosest having the highest textual similarity with Mi
C6
Detecting Feature Envy instances
method1()method2()
…methodN()
Cclosest
Feature Envy Probability Computation
method1()method2()
…methodN()
CO
Empirical Study
TACO - Evaluating its performance
10 software systems
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
TACO - Evaluating its performance
10 software systems
PrecisionRecall
F-Measure
Oracle available from Landfill
10 software systems
TACO - Evaluating its performance
PrecisionRecall
F-Measure
Oracle available from Landfill
Overlap Metrics
TACO
Alternative Structural Technique
TACO && Alternative
Structural Technique
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
TACO - Overall F-Measure
TACOAlternative Structural Technique
+22%on average in terms of F-Measure
TACO - Overall F-Measure
TACO - A practical example Method: findTypesAndPackages()
Goal: Discover the classes and the packages of a given project
Class: CompletionEngine - Eclipse Core
Method: findTypesAndPackages()
Goal: Discover the classes and the packages of a given project
Class: CompletionEngine - Eclipse Core
65lines of code
TACO - A practical example
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
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
TACO - Evaluating the complementarity with structural approaches
TACOAlternative Structural TechniqueOverlap
Textual and Structural Information
are Highly Complementary
What about a combined technique for smell detection?
Do developers perceive textual smells as actual design flaws?
Is TACO able to detect other code smells?
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