Do They Really Smell Bad? A Study on Developers' Perception of Bad Code Smells

58
Do They Really Smell Bad? A Study on Developers’ Perception of Bad Code Smells Fabio Palomba , Gabriele Bavota, Massimiliano Di Penta, Rocco Oliveto, Andrea De Lucia ICSME 2014 Victoria - Canada October 1st, 2014 giovedì 2 ottobre 14

description

In the last decade several catalogues have been defined to characterize bad code smells, i.e., symptoms of poor design and implementation choices. On top of such catalogues, researchers have defined methods and tools to automatically detect and/or remove bad smells. Nevertheless, there is an ongoing debate regarding the extent to which developers perceive bad smells as serious design problems. Indeed, there seems to be a gap between theory and practice, i.e., what is believed to be a problem (theory) and what is actually a problem (practice). This paper presents a study aimed at providing empirical evidence on how developers perceive bad smells. In this study, we showed to developers code entities—belonging to three systems— affected and not by bad smells, and we asked them to indicate whether the code contains a potential design problem, and if any, the nature and severity of the problem. The study involved both original developers from the three projects and outsiders, namely industrial developers and Master students. The results provide insights on characteristics of bad smells not yet explored sufficiently. Also, our findings could guide future research on approaches for the detection and removal of bad smells.

Transcript of Do They Really Smell Bad? A Study on Developers' Perception of Bad Code Smells

Page 1: Do They Really Smell Bad? A Study on Developers' Perception of Bad Code Smells

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

giovedì 2 ottobre 14

Page 2: Do They Really Smell Bad? A Study on Developers' Perception of Bad Code Smells

giovedì 2 ottobre 14

Page 3: Do They Really Smell Bad? A Study on Developers' Perception of Bad Code Smells

giovedì 2 ottobre 14

Page 4: Do They Really Smell Bad? A Study on Developers' Perception of Bad Code Smells

giovedì 2 ottobre 14

Page 5: Do They Really Smell Bad? A Study on Developers' Perception of Bad Code Smells

giovedì 2 ottobre 14

Page 6: Do They Really Smell Bad? A Study on Developers' Perception of Bad Code Smells

Context

Bad Code Smells

giovedì 2 ottobre 14

Page 7: Do They Really Smell Bad? A Study on Developers' Perception of Bad Code Smells

Bad Code Smells

giovedì 2 ottobre 14

Page 8: Do They Really Smell Bad? A Study on Developers' Perception of Bad Code Smells

Moha et al., “DECOR: A Method for the Specification and Detection of Code and Design Smells” - TSE 2010

giovedì 2 ottobre 14

Page 9: Do They Really Smell Bad? A Study on Developers' Perception of Bad Code Smells

van Emden et al., “Java Quality Assurance by Detecting Code Smells” - WCRE 2002

giovedì 2 ottobre 14

Page 10: Do They Really Smell Bad? A Study on Developers' Perception of Bad Code Smells

Tsantalis et al., “Identification of Move Method Refactoring Opportunities” - TSE 2009

Fokaets et al., “Identification and Application of Extract Class Refactorings In Object Oriented Systems” - JSS 2012

Tsantalis et al., “Identification of Extract Method Refactoring Opportunities for the Decomposition of Methods” - JSS 2011

giovedì 2 ottobre 14

Page 11: Do They Really Smell Bad? A Study on Developers' Perception of Bad Code Smells

Kessentini et al., “Deviance from Perfection is a Better Criterion than Closeness to Evil when Identifying Risky Code” - ASE 2010

giovedì 2 ottobre 14

Page 12: Do They Really Smell Bad? A Study on Developers' Perception of Bad Code Smells

Palomba et al., “Detecting Bad Smells in Source Code using Change History Information” - ASE 2013

giovedì 2 ottobre 14

Page 13: Do They Really Smell Bad? A Study on Developers' Perception of Bad Code Smells

Abebe et al., “Lexicon Bad Smells in Software” - WCRE 2009

giovedì 2 ottobre 14

Page 14: Do They Really Smell Bad? A Study on Developers' Perception of Bad Code Smells

Not only detection techniques! But also...

giovedì 2 ottobre 14

Page 15: Do They Really Smell Bad? A Study on Developers' Perception of Bad Code Smells

A. Chatzigeorgiou et al., “Investigating the evolution of bad smells in object-oriented code” - QUATIC 2010

giovedì 2 ottobre 14

Page 16: Do They Really Smell Bad? A Study on Developers' Perception of Bad Code Smells

R. Peters and A. Zaidman, “Evaluating the lifespan of code smells using software repository mining” - CSMR 2012

R. Arcoverde, A. Garcia, and E. Figueiredo, “Understanding the longevity of code smells: preliminary results of an explanatory survey” - IWRT 2011

giovedì 2 ottobre 14

Page 17: Do They Really Smell Bad? A Study on Developers' Perception of Bad Code Smells

F. Khomh, M. Di Penta, Y.-G. Guéhéneuc, and G. Antoniol, “An exploratory study of the impact of antipatterns on class change- and fault-proneness” - EMSE 2012

W. Li and R. Shatnawi, “An empirical study of the bad smells and class error probability in the post-release object-oriented system evolution” - JSS 2007

giovedì 2 ottobre 14

Page 18: Do They Really Smell Bad? A Study on Developers' Perception of Bad Code Smells

M. Abbes, F. Khomh,Y.-G. Guéhéneuc, and G. Antoniol, “An empirical study of the impact of two antipatterns, blob and spaghetti code, on program comprehension” - CSMR 2011

giovedì 2 ottobre 14

Page 19: Do They Really Smell Bad? A Study on Developers' Perception of Bad Code Smells

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

giovedì 2 ottobre 14

Page 20: Do They Really Smell Bad? A Study on Developers' Perception of Bad Code Smells

S. M. Olbrich, D. S. Cruzes, and D. I. K. Sjøberg, “Are all code smells harmful? A study of God Classes and Brain Classes in the evolution of three open source systems” - ICSM 2010

giovedì 2 ottobre 14

Page 21: Do They Really Smell Bad? A Study on Developers' Perception of Bad Code Smells

A. Yamashita and L. Moonen, “Do developers care about code smells? An exploratory survey” - WCRE 2013

giovedì 2 ottobre 14

Page 22: Do They Really Smell Bad? A Study on Developers' Perception of Bad Code Smells

Investingating the developers’ point of view

giovedì 2 ottobre 14

Page 23: Do They Really Smell Bad? A Study on Developers' Perception of Bad Code Smells

RQ1: To what extent do bad smells reflect developers’ perception of design problems?

Investingating the developers’ point of view

giovedì 2 ottobre 14

Page 24: Do They Really Smell Bad? A Study on Developers' Perception of Bad Code Smells

RQ1: To what extent do bad smells reflect developers’ perception of design problems?

Investingating the developers’ point of view

RQ2: What are the bad smells that developers feel as the most harmful?

giovedì 2 ottobre 14

Page 25: Do They Really Smell Bad? A Study on Developers' Perception of Bad Code Smells

Study Design

giovedì 2 ottobre 14

Page 26: Do They Really Smell Bad? A Study on Developers' Perception of Bad Code Smells

Study DesignClass Data Should Be Private

Complex ClassFeature Envy

God ClassInappropriate Intimacy

Lazy ClassLong Method

Long Parameter ListMiddle Man

Refused BequestSpaghetti Code

Speculative Generality

giovedì 2 ottobre 14

Page 27: Do They Really Smell Bad? A Study on Developers' Perception of Bad Code Smells

Study DesignClass Data Should Be Private

Complex ClassFeature Envy

God ClassInappropriate Intimacy

Lazy ClassLong Method

Long Parameter ListMiddle Man

Refused BequestSpaghetti Code

Speculative Generality

Argo UML 0.34Eclipse 3.6.1

jEdit 4.5.1

giovedì 2 ottobre 14

Page 28: Do They Really Smell Bad? A Study on Developers' Perception of Bad Code Smells

Study Design

Original Developers: 10

Industrial Developers9

Master’s Students15

Argo UML 0.34Eclipse 3.6.1

jEdit 4.5.1

Class Data Should Be PrivateComplex Class

Feature EnvyGod Class

Inappropriate IntimacyLazy Class

Long MethodLong Parameter List

Middle ManRefused BequestSpaghetti Code

Speculative Generality

giovedì 2 ottobre 14

Page 29: Do They Really Smell Bad? A Study on Developers' Perception of Bad Code Smells

Study Design

Smelly Class

Developer

giovedì 2 ottobre 14

Page 30: Do They Really Smell Bad? A Study on Developers' Perception of Bad Code Smells

Study Design

Smelly Class

Developer

In your opinion, does this code component exhibit any design and/or implementation problem?

giovedì 2 ottobre 14

Page 31: Do They Really Smell Bad? A Study on Developers' Perception of Bad Code Smells

Study Design

Smelly Class

Developer

In your opinion, does this code component exhibit any design and/or implementation problem?

• If YES, please explain what are, in your opinion, the problems affecting the code component.

giovedì 2 ottobre 14

Page 32: Do They Really Smell Bad? A Study on Developers' Perception of Bad Code Smells

Study Design

Smelly Class

Developer

In your opinion, does this code component exhibit any design and/or implementation problem?

• If YES, please explain what are, in your opinion, the problems affecting the code component.

• If YES, please rate the severity of the design and/or implementation problem by assigning a score on the following five-points Likert scale: 1 (very low), 2 (low), 3 (medium), 4 (high), 5 (very high).

giovedì 2 ottobre 14

Page 33: Do They Really Smell Bad? A Study on Developers' Perception of Bad Code Smells

Resultsgiovedì 2 ottobre 14

Page 34: Do They Really Smell Bad? A Study on Developers' Perception of Bad Code Smells

Smells generally not Perceived as Design or Implementation Problems

Class Data Should Be Private

Middle Man

Lazy Class

Inappropriate Intimacy

Long Parameter List

giovedì 2 ottobre 14

Page 35: Do They Really Smell Bad? A Study on Developers' Perception of Bad Code Smells

Smells generally not Perceived as Design or Implementation Problems

Class Data Should Be Private

Middle Man

Lazy Class

Inappropriate Intimacy

< 25% perceived < 24% IDENTIFIED

< 10% perceived < 5% IDENTIFIED

< 36% PERCEIVED

< 20% PERCEIVED

< 30% PERCEIVED

< 20% IDENTIFIED

< 5% IDENTIFIED

< 13% IDENTIFIED

Long Parameter List

giovedì 2 ottobre 14

Page 36: Do They Really Smell Bad? A Study on Developers' Perception of Bad Code Smells

Smells generally not Perceived as Design or Implementation Problems

Class Data Should Be Private < 25% perceived < 24% IDENTIFIED

0

5

10

15

20

25

30

M I O

Identified Perceived

giovedì 2 ottobre 14

Page 37: Do They Really Smell Bad? A Study on Developers' Perception of Bad Code Smells

Smells generally not Perceived as Design or Implementation Problems

Class Data Should Be Private < 25% perceived < 24% IDENTIFIED

0

5

10

15

20

25

30

M I O

Identified Perceived

M I O

Severity

1 2 2

giovedì 2 ottobre 14

Page 38: Do They Really Smell Bad? A Study on Developers' Perception of Bad Code Smells

Smells generally not Perceived as Design or Implementation Problems

Class Data Should Be Private < 25% perceived < 24% IDENTIFIED

0

5

10

15

20

25

30

M I O

Identified Perceived

M I O

Severity

“This class exposes all its fields, and this could look like bad coding.

However, at the end of the day this is an utility class with public static

fields that can be used from everywhere in the system”

giovedì 2 ottobre 14

Page 39: Do They Really Smell Bad? A Study on Developers' Perception of Bad Code Smells

Smells generally Perceived and Identified by Respondents

Complex Class

God Class

Long Method

Spaghetti Code

giovedì 2 ottobre 14

Page 40: Do They Really Smell Bad? A Study on Developers' Perception of Bad Code Smells

Smells generally Perceived and Identified by Respondents

Complex Class

God Class

Long Method

Spaghetti Code

> 85% perceived > 83% IDENTIFIED

> 75% perceived > 75% IDENTIFIED

> 70% perceived > 70% IDENTIFIED

> 68% perceived < 65% IDENTIFIED

giovedì 2 ottobre 14

Page 41: Do They Really Smell Bad? A Study on Developers' Perception of Bad Code Smells

Smells generally Perceived and Identified by Respondents

God Class

0

17

33

50

67

83

100

M I O

Identified Perceived

> 85% perceived > 83% IDENTIFIED

giovedì 2 ottobre 14

Page 42: Do They Really Smell Bad? A Study on Developers' Perception of Bad Code Smells

Smells generally Perceived and Identified by Respondents

God Class

0

17

33

50

67

83

100

M I O

Identified Perceived

M I O

Severity

> 85% perceived > 83% IDENTIFIED

4 5 5

giovedì 2 ottobre 14

Page 43: Do They Really Smell Bad? A Study on Developers' Perception of Bad Code Smells

Refused Bequest

Smells whose Perception may vary

Speculative Generality

Feature Envy

giovedì 2 ottobre 14

Page 44: Do They Really Smell Bad? A Study on Developers' Perception of Bad Code Smells

Refused Bequest

Smells whose Perception may vary

Speculative Generality

Feature Envy

DEPENDS FROM

THE “INTENSITY” OF

THE PROBLEM

giovedì 2 ottobre 14

Page 45: Do They Really Smell Bad? A Study on Developers' Perception of Bad Code Smells

Smells whose Perception may vary

Refused Bequest

0102030405060708090

100

ArgoUML Eclipse jEdit

Perceived Identified

Master Students Perception on the Three Analyzed Systems

giovedì 2 ottobre 14

Page 46: Do They Really Smell Bad? A Study on Developers' Perception of Bad Code Smells

Smells whose Perception may vary

Refused Bequest Master Students Perception on the Three Analyzed Systems

0102030405060708090

100

ArgoUML Eclipse jEdit

Perceived Identified

1

1

4

giovedì 2 ottobre 14

Page 47: Do They Really Smell Bad? A Study on Developers' Perception of Bad Code Smells

Conclusion

giovedì 2 ottobre 14

Page 48: Do They Really Smell Bad? A Study on Developers' Perception of Bad Code Smells

giovedì 2 ottobre 14

Page 49: Do They Really Smell Bad? A Study on Developers' Perception of Bad Code Smells

giovedì 2 ottobre 14

Page 50: Do They Really Smell Bad? A Study on Developers' Perception of Bad Code Smells

giovedì 2 ottobre 14

Page 51: Do They Really Smell Bad? A Study on Developers' Perception of Bad Code Smells

giovedì 2 ottobre 14

Page 52: Do They Really Smell Bad? A Study on Developers' Perception of Bad Code Smells

giovedì 2 ottobre 14

Page 53: Do They Really Smell Bad? A Study on Developers' Perception of Bad Code Smells

giovedì 2 ottobre 14

Page 54: Do They Really Smell Bad? A Study on Developers' Perception of Bad Code Smells

giovedì 2 ottobre 14

Page 55: Do They Really Smell Bad? A Study on Developers' Perception of Bad Code Smells

giovedì 2 ottobre 14

Page 56: Do They Really Smell Bad? A Study on Developers' Perception of Bad Code Smells

giovedì 2 ottobre 14

Page 57: Do They Really Smell Bad? A Study on Developers' Perception of Bad Code Smells

giovedì 2 ottobre 14

Page 58: Do They Really Smell Bad? A Study on Developers' Perception of Bad Code Smells

?giovedì 2 ottobre 14