![Page 1: A Textual-based Technique for Smell Detection](https://reader031.vdocuments.net/reader031/viewer/2022030201/58a625a61a28ab416c8b5207/html5/thumbnails/1.jpg)
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](https://reader031.vdocuments.net/reader031/viewer/2022030201/58a625a61a28ab416c8b5207/html5/thumbnails/2.jpg)
“Bad Code Smells are symptoms of poor design or implementation choices”
[Martin Fowler]
![Page 3: A Textual-based Technique for Smell Detection](https://reader031.vdocuments.net/reader031/viewer/2022030201/58a625a61a28ab416c8b5207/html5/thumbnails/3.jpg)
[Abbes et al. - CSMR 2011]Bad Smells hinder code comprehensibility
![Page 4: A Textual-based Technique for Smell Detection](https://reader031.vdocuments.net/reader031/viewer/2022030201/58a625a61a28ab416c8b5207/html5/thumbnails/4.jpg)
[Khomh et al. - EMSE 2012]
Bad Smells increase change- and bug-proneness
![Page 5: A Textual-based Technique for Smell Detection](https://reader031.vdocuments.net/reader031/viewer/2022030201/58a625a61a28ab416c8b5207/html5/thumbnails/5.jpg)
[Banker et al. - Comm. of the ACM]Bad Smells increase maintenance costs
![Page 6: A Textual-based Technique for Smell Detection](https://reader031.vdocuments.net/reader031/viewer/2022030201/58a625a61a28ab416c8b5207/html5/thumbnails/6.jpg)
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](https://reader031.vdocuments.net/reader031/viewer/2022030201/58a625a61a28ab416c8b5207/html5/thumbnails/7.jpg)
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](https://reader031.vdocuments.net/reader031/viewer/2022030201/58a625a61a28ab416c8b5207/html5/thumbnails/8.jpg)
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](https://reader031.vdocuments.net/reader031/viewer/2022030201/58a625a61a28ab416c8b5207/html5/thumbnails/9.jpg)
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](https://reader031.vdocuments.net/reader031/viewer/2022030201/58a625a61a28ab416c8b5207/html5/thumbnails/10.jpg)
Structural and Historical Analysis are only a part of the whole story
![Page 11: A Textual-based Technique for Smell Detection](https://reader031.vdocuments.net/reader031/viewer/2022030201/58a625a61a28ab416c8b5207/html5/thumbnails/11.jpg)
/* 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](https://reader031.vdocuments.net/reader031/viewer/2022030201/58a625a61a28ab416c8b5207/html5/thumbnails/12.jpg)
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](https://reader031.vdocuments.net/reader031/viewer/2022030201/58a625a61a28ab416c8b5207/html5/thumbnails/13.jpg)
TACO
Textual Analysis forCode smell detectiOn
![Page 14: A Textual-based Technique for Smell Detection](https://reader031.vdocuments.net/reader031/viewer/2022030201/58a625a61a28ab416c8b5207/html5/thumbnails/14.jpg)
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](https://reader031.vdocuments.net/reader031/viewer/2022030201/58a625a61a28ab416c8b5207/html5/thumbnails/15.jpg)
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](https://reader031.vdocuments.net/reader031/viewer/2022030201/58a625a61a28ab416c8b5207/html5/thumbnails/16.jpg)
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](https://reader031.vdocuments.net/reader031/viewer/2022030201/58a625a61a28ab416c8b5207/html5/thumbnails/17.jpg)
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](https://reader031.vdocuments.net/reader031/viewer/2022030201/58a625a61a28ab416c8b5207/html5/thumbnails/18.jpg)
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](https://reader031.vdocuments.net/reader031/viewer/2022030201/58a625a61a28ab416c8b5207/html5/thumbnails/19.jpg)
Detecting Feature Envy instances
![Page 20: A Textual-based Technique for Smell Detection](https://reader031.vdocuments.net/reader031/viewer/2022030201/58a625a61a28ab416c8b5207/html5/thumbnails/20.jpg)
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](https://reader031.vdocuments.net/reader031/viewer/2022030201/58a625a61a28ab416c8b5207/html5/thumbnails/21.jpg)
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](https://reader031.vdocuments.net/reader031/viewer/2022030201/58a625a61a28ab416c8b5207/html5/thumbnails/22.jpg)
Empirical Study
![Page 23: A Textual-based Technique for Smell Detection](https://reader031.vdocuments.net/reader031/viewer/2022030201/58a625a61a28ab416c8b5207/html5/thumbnails/23.jpg)
TACO - Evaluating its performance
10 software systems
![Page 24: A Textual-based Technique for Smell Detection](https://reader031.vdocuments.net/reader031/viewer/2022030201/58a625a61a28ab416c8b5207/html5/thumbnails/24.jpg)
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](https://reader031.vdocuments.net/reader031/viewer/2022030201/58a625a61a28ab416c8b5207/html5/thumbnails/25.jpg)
TACO - Evaluating its performance
10 software systems
PrecisionRecall
F-Measure
Oracle available from Landfill
![Page 26: A Textual-based Technique for Smell Detection](https://reader031.vdocuments.net/reader031/viewer/2022030201/58a625a61a28ab416c8b5207/html5/thumbnails/26.jpg)
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](https://reader031.vdocuments.net/reader031/viewer/2022030201/58a625a61a28ab416c8b5207/html5/thumbnails/27.jpg)
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](https://reader031.vdocuments.net/reader031/viewer/2022030201/58a625a61a28ab416c8b5207/html5/thumbnails/28.jpg)
TACO - Overall F-Measure
TACOAlternative Structural Technique
![Page 29: A Textual-based Technique for Smell Detection](https://reader031.vdocuments.net/reader031/viewer/2022030201/58a625a61a28ab416c8b5207/html5/thumbnails/29.jpg)
+22%on average in terms of F-Measure
TACO - Overall F-Measure
![Page 30: A Textual-based Technique for Smell Detection](https://reader031.vdocuments.net/reader031/viewer/2022030201/58a625a61a28ab416c8b5207/html5/thumbnails/30.jpg)
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](https://reader031.vdocuments.net/reader031/viewer/2022030201/58a625a61a28ab416c8b5207/html5/thumbnails/31.jpg)
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](https://reader031.vdocuments.net/reader031/viewer/2022030201/58a625a61a28ab416c8b5207/html5/thumbnails/32.jpg)
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](https://reader031.vdocuments.net/reader031/viewer/2022030201/58a625a61a28ab416c8b5207/html5/thumbnails/33.jpg)
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](https://reader031.vdocuments.net/reader031/viewer/2022030201/58a625a61a28ab416c8b5207/html5/thumbnails/34.jpg)
TACO - Evaluating the complementarity with structural approaches
TACOAlternative Structural TechniqueOverlap
![Page 35: A Textual-based Technique for Smell Detection](https://reader031.vdocuments.net/reader031/viewer/2022030201/58a625a61a28ab416c8b5207/html5/thumbnails/35.jpg)
Textual and Structural Information
are Highly Complementary
![Page 36: A Textual-based Technique for Smell Detection](https://reader031.vdocuments.net/reader031/viewer/2022030201/58a625a61a28ab416c8b5207/html5/thumbnails/36.jpg)
What about a combined technique for smell detection?
![Page 37: A Textual-based Technique for Smell Detection](https://reader031.vdocuments.net/reader031/viewer/2022030201/58a625a61a28ab416c8b5207/html5/thumbnails/37.jpg)
Do developers perceive textual smells as actual design flaws?
![Page 38: A Textual-based Technique for Smell Detection](https://reader031.vdocuments.net/reader031/viewer/2022030201/58a625a61a28ab416c8b5207/html5/thumbnails/38.jpg)
Is TACO able to detect other code smells?
![Page 39: A Textual-based Technique for Smell Detection](https://reader031.vdocuments.net/reader031/viewer/2022030201/58a625a61a28ab416c8b5207/html5/thumbnails/39.jpg)
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