Understanding mobile-specific code smells Presented by: Sarra - - PowerPoint PPT Presentation

understanding mobile specific code smells
SMART_READER_LITE
LIVE PREVIEW

Understanding mobile-specific code smells Presented by: Sarra - - PowerPoint PPT Presentation

Understanding mobile-specific code smells Presented by: Sarra Habchi Advisor: Examiners: - Romain Rouvoy - Jean-Christophe Routier Rapporteurs: - Naouel Moha - Andy Zaidman - Tegawend-Franois Bissyande - Yann-Gal Guhneuc


slide-1
SLIDE 1

Understanding mobile-specific code smells

Presented by:

Sarra Habchi

Examiners:

  • Jean-Christophe Routier
  • Naouel Moha
  • Tegawendé-François Bissyande

Advisor:

  • Romain Rouvoy

Rapporteurs:

  • Andy Zaidman
  • Yann-Gaël Guéhéneuc
slide-2
SLIDE 2

Raconteur.net 2

slide-3
SLIDE 3

3

slide-4
SLIDE 4

4

slide-5
SLIDE 5

5

slide-6
SLIDE 6

6

slide-7
SLIDE 7

7

slide-8
SLIDE 8

8

slide-9
SLIDE 9

Performance matters!

9

slide-10
SLIDE 10

Performance practices matter!

10

slide-11
SLIDE 11

11

Performance bad practices

slide-12
SLIDE 12

12

Performance bad practices

  • Resource leaks (Guo et al. 2013)
  • 3 anti-patterns (Liu et al. 2014)
  • 30 code smells (Reimann et al. 2014)

→ Mobile-specific code smells

slide-13
SLIDE 13

13

Mobile-specific code smells

  • Catalog
  • Reused & extended in later studies
  • 14 studies
slide-14
SLIDE 14

Semi-automated analysis Official documentation Developer blogs & talks Q&A forums Catalog of 30 Android code smells ... performance

14

slide-15
SLIDE 15

15

UI Overdraw

slide-16
SLIDE 16

1 overdraw 2 overdraws 3 overdraws 4 overdraws

16

slide-17
SLIDE 17

17

Detection tools

slide-18
SLIDE 18

18

Detection tools

  • Paprika (Hecht et al. 2015)
  • aDoctor (Palomba et al. 2017)
  • MOGP approach (Kessentini and Ouni

2017)

slide-19
SLIDE 19

19

Impact on performance

slide-20
SLIDE 20

20

Impact on performance

  • UI & Memory (Hecht et al. 2016)
  • Energy (Carette et al. 2017)
  • Energy (Palomba et al. 2019)
slide-21
SLIDE 21

21

Code smell catalog Impact on performance Detection tools

?

slide-22
SLIDE 22

22

slide-23
SLIDE 23

Causes Relevance Adequate tools

23

slide-24
SLIDE 24

24

Code smell catalog Impact on performance Understand code smells Refactoring catalog Refactoring tools Detection tools

We have: We lack:

slide-25
SLIDE 25

Understanding mobile code smells

  • 1. Extent
  • 2. Causes
  • 3. Developers’ perception

25

slide-26
SLIDE 26

Understanding mobile code smells

  • 1. Extent
  • 2. Causes
  • 3. Developers’ perception

26

slide-27
SLIDE 27

27

slide-28
SLIDE 28

Code Smells in iOS Apps: How do they compare to Android?

  • Identified 6 iOS-specific code smells
  • Common code smells between Android and iOS
  • Proposed a detection tool for iOS
  • Android apps tend to have more smells than the iOS ones

28

slide-29
SLIDE 29

Understanding mobile code smells

  • 1. Extent
  • 2. Causes
  • 3. Developers’ perception

29

slide-30
SLIDE 30

Understanding mobile code smells

  • 1. Extent
  • 2. Causes
  • 3. Developers’ perception

30

slide-31
SLIDE 31

31

Pragmatism Prioritisation Process Attitudes Ignorance Oversight

Motives of technical debt (Tom et al. 2013)

slide-32
SLIDE 32

32

Pragmatism Prioritisation Process Attitudes Ignorance Oversight

Motives of technical debt (Tom et al. 2013)

slide-33
SLIDE 33

33

Pragmatism Prioritisation Process Attitudes Ignorance Oversight

Motives of technical debt (Tom et al. 2013)

slide-34
SLIDE 34

34

slide-35
SLIDE 35

35

1- Commits 2- Developers 3- Survival

slide-36
SLIDE 36

36

1- Commits 2- Developers 3- Survival

slide-37
SLIDE 37

Commit0 Commit1 Commitk Commitn

... ...

Code smell introduction Code smell removal

Instance A Instance A Instance B Instance A Instance B Instance A

37

slide-38
SLIDE 38

Commit0 Commit1 Commitk Commitn

... ...

Instance A Instance A Instance B Instance A Instance B Instance A

38

Commitm Commitp

...

Instance A Instance A Instance C

slide-39
SLIDE 39

39 RegistrationSocket.java GcmSocket.java Commit 303d1ac: File renaming

Instance

RegistrationSocket$Verification

Instance

GcmSocket$Verification

link

slide-40
SLIDE 40

Branches + Renamings

40

slide-41
SLIDE 41

41

slide-42
SLIDE 42

Sniffer

42

Commits Git link to an app 1-Extract app data Repository model Instances 3- Analyse change history 2- Detect code smells Full code smell history

slide-43
SLIDE 43

Sniffer

  • Track branches
  • Detect renamings
  • Validated with:

○ F1-score=0.96

43

slide-44
SLIDE 44

Dataset

  • 324 open-source apps
  • 255,000 commits
  • 4,525 developers

44

slide-45
SLIDE 45

45

LIC Leaking Inner Class MIM Member Ignoring Method NLMR No Low Memory Resolver HMU HashMap Usage UIO UI Overdraw UHA Unsupported Hardware Acceleration IOD Init OnDraw UCS Unsuited Cache Size

slide-46
SLIDE 46

46

Introductions

slide-47
SLIDE 47

47

% Removals

slide-48
SLIDE 48

79% of code smell instances are removed

48

slide-49
SLIDE 49

Intended removal?

49

slide-50
SLIDE 50

50

No Low Memory Resolver

slide-51
SLIDE 51

51

slide-52
SLIDE 52

52

slide-53
SLIDE 53

Source code deletion

53

slide-54
SLIDE 54

54

% Removals by deletion

slide-55
SLIDE 55

59% of code smell removals are accompanied with source code deletion

55

slide-56
SLIDE 56

Manual analysis

  • 561 code smell instances

○ Commit actions ○ Commit message

56

slide-57
SLIDE 57

How are code smells removed?

  • Removal is a side effect of evolution

○ Source code deleted ○ Empty methods filled (MIM)

57

slide-58
SLIDE 58

How are code smells removed?

  • Only refactoring:

○ Code smells detected by Android Lint ■ Init OnDraw (IOD) ■ UI Overdraw (UIO)

58

slide-59
SLIDE 59

Most of code smell removals are a side-effect of other activities

59

slide-60
SLIDE 60

60

Pragmatism Prioritisation Process Attitudes Ignorance Oversight

Motives of technical debt

slide-61
SLIDE 61

61

How do releases impact code smell introductions and removals?

slide-62
SLIDE 62

1 Day 1 Week 1 Month

62

slide-63
SLIDE 63

63

Releases do not have any impact on code smell introductions or removals.

slide-64
SLIDE 64

64

Pragmatism Prioritisation Process Attitudes Ignorance Oversight

Motives of technical debt

slide-65
SLIDE 65

65

1- Commits 2- Developers 3- Survival

slide-66
SLIDE 66

66

1- Commits 2- Developers 3- Survival

slide-67
SLIDE 67

67

slide-68
SLIDE 68

Who is involved?

68

slide-69
SLIDE 69

69

slide-70
SLIDE 70

38%

Mainly 1 commit

70

slide-71
SLIDE 71

Involved developers

71

slide-72
SLIDE 72

Introducers Removers

72

slide-73
SLIDE 73

Introducers 18%

73

slide-74
SLIDE 74

Introducers Removers BOTH 18% 8%

74

slide-75
SLIDE 75

Expected

75

Introductions Removals

slide-76
SLIDE 76

76

⍴ = 0.77

slide-77
SLIDE 77

77

Introducers ≃ Removers

slide-78
SLIDE 78

Seniority and code smells

78

  • Contribution = commits/project size
  • Reputation ≃ followers

“Developers with lots of followers were treated as local

  • celebrities. Their activities were retold almost as local

parable”

(Dabbish et al. 2012)

slide-79
SLIDE 79

79

⍴ = 0.27 ⍴ = 0.24

slide-80
SLIDE 80

80

Senior Junior

→ Seniority does not impact developers’ behavior

Senior Junior

slide-81
SLIDE 81
  • Introducers ⋍ Removers
  • Newcomer ⟹ Bad contributor ฀
  • Senior || Reputable ⟹ Good contributor ฀

81

slide-82
SLIDE 82

82

Pragmatism Prioritisation Process Attitudes Ignorance Oversight

Motives of technical debt

82

slide-83
SLIDE 83

83

1- Commits 2- Developers 3- Survival

slide-84
SLIDE 84

84

1- Commits 2- Developers 3- Survival

slide-85
SLIDE 85

85

slide-86
SLIDE 86

Survival analysis

  • S(t) = Probability(t < T)
  • T: a random lifetime from the population

“Chances for a code smell to be still present in the source code after t time”

  • 180.000 code smell lifelines

86

slide-87
SLIDE 87

87

441 days 14 months

slide-88
SLIDE 88

88

9 commits

slide-89
SLIDE 89

14 months vs. 9 effective commits

89

slide-90
SLIDE 90

Variables: project properties

  • Project size

○ #Classes ○ #Commits ○ #Developers

  • Project releases

○ #Releases ○ Cycle

90

slide-91
SLIDE 91

Variables: Code smell properties

  • Tool integration

○ Linted (detectable by Android Lint) ○ Linter priority

  • Code smell type

○ Granularity

91

slide-92
SLIDE 92

Variables: Code smell properties

  • Tool integration

○ Linted (detectable by Android Lint) ○ Linter priority

  • Code smell type

○ Granularity

92

slide-93
SLIDE 93

93

→ Static analysers have an impact on mobile code smells → Tool prioritisation matters

slide-94
SLIDE 94

94

slide-95
SLIDE 95

95

Pragmatism Prioritisation Process Attitudes Ignorance Oversight

Motives of technical debt

95

slide-96
SLIDE 96

Understanding mobile code smells

  • 1. Extent
  • 2. Causes:
  • Change history
  • 3. Developers’ perception

96

slide-97
SLIDE 97

Understanding mobile code smells

  • 1. Extent
  • 2. Causes:
  • Change history
  • 3. Developers’ perception

97

slide-98
SLIDE 98

98

slide-99
SLIDE 99

Catalog of performance code smells

How do they use the linter to deal with performance concerns?

99

slide-100
SLIDE 100

Semi-structured Interviews Experienced Android developers Qualitative approach Analytical strategy

  • f

(Schmidt et al. 2004)

100 100

slide-101
SLIDE 101
  • Benefits
  • Fashions
  • Challenges

101 101

slide-102
SLIDE 102
  • Benefits
  • Fashions
  • Challenges

102 102

slide-103
SLIDE 103

Benefits

  • Anticipate performance bottlenecks
  • Develop performance culture and awareness
  • Learn about the framework
  • Save time
  • Maintain credibility and reputation
  • Ease performance debugging

103 103

slide-104
SLIDE 104

Benefits

  • Anticipate performance bottlenecks
  • Develop performance culture and awareness
  • Learn about the framework
  • Save time
  • Maintain credibility and reputation
  • Ease performance debugging

104 104

slide-105
SLIDE 105

«We can disagree on whether to consider the linter suggestions or not, so we will discuss and understand the problem, then make a wise decision about it»

105

Performance culture

105

slide-106
SLIDE 106

«It will give me a time or a moment to think and

  • decide. If I am the only developer, for me this

thinking is critical»

106

Performance awareness

106

slide-107
SLIDE 107
  • Benefits
  • Fashions
  • Challenges

107 107

slide-108
SLIDE 108
  • Benefits
  • Fashions
  • Challenges

108 108

slide-109
SLIDE 109

Challenges

  • Nobody complained
  • The code smells are irrelevant
  • False positives
  • Static analysis is not suitable for performance
  • Performance is not important in our case
  • We do not have time
  • The difficulty of writing new rules
  • Poverty

109 109

slide-110
SLIDE 110

Challenges

  • Nobody complained
  • The code smells are irrelevant
  • False positives
  • Static analysis is not suitable for performance
  • Performance is not important in our case
  • We do not have time
  • The difficulty of writing new rules
  • Poverty

110 110

slide-111
SLIDE 111

111

slide-112
SLIDE 112

«With performance you do not want to do a lot, you want to make sure that you are really looking at the issue and not trying to over optimise the code»

112

Nobody complained

112

slide-113
SLIDE 113

Challenges

  • Nobody complained
  • The code smells are irrelevant
  • Imprecision
  • Static analysis is not suitable for performance
  • Performance is not important in our case
  • We do not have time
  • The difficulty of writing new rules
  • Poverty

113 113

slide-114
SLIDE 114

Challenges

  • Nobody complained
  • The code smells are irrelevant
  • Imprecision
  • Static analysis is not suitable for performance
  • Performance is not important in our case
  • We do not have time
  • The difficulty of writing new rules
  • Poverty

114 114

slide-115
SLIDE 115

Critiques

115

slide-116
SLIDE 116

«Developers are obsessed with Overdraw. It became a cult actually, but this is not what really hinders the performance of your app»

116

Code smells are irrelevant

116

slide-117
SLIDE 117

«Performance issues are very complicated or have multiple causes that cannot be pinpointed to a one line of Java code»

117

Static analysis

117

slide-118
SLIDE 118

Implications for researchers

  • (Re-)evaluate the relevance and impact of performance

bad practices in mobile apps

118

slide-119
SLIDE 119

Understanding mobile code smells

  • 1. Extent
  • 2. Causes:
  • Change history
  • 3. Developers’ perception

119

slide-120
SLIDE 120

Understanding mobile code smells

  • 1. Extent
  • 2. Causes:
  • Change history
  • 3. Developers’ perception
  • 4. Reassessment

120

slide-121
SLIDE 121

121 121

slide-122
SLIDE 122

Qualitative investigation Descriptive and Inductive Sample of 599 code smell instances Literature about:

  • Mobile apps
  • Performance

122 122

slide-123
SLIDE 123

123

Code smell The definition omits The definition leads to No Low Memory Resolver Alternative means to avoid the code smell False positives UI Overdraw HashMap Usage Technical details Leaking Inner Class Prevalent programming fashions Occurrences that are:

  • inevitable and/or
  • hard to refactor

Member Ignoring Method Unsupported Hardware Acceleration Absence of alternatives

slide-124
SLIDE 124

124

Code smell The definition omits The definition leads to No Low Memory Resolver Alternative means to avoid the code smell False positives UI Overdraw HashMap Usage Technical details Leaking Inner Class Prevalent programming fashions Occurrences that are:

  • inevitable and/or
  • hard to refactor

Member Ignoring Method Unsupported Hardware Acceleration Absence of alternatives

slide-125
SLIDE 125

125

Code smell The definition omits The definition leads to No Low Memory Resolver Alternative means to avoid the code smell False positives UI Overdraw HashMap Usage Technical details Leaking Inner Class Prevalent programming fashions Occurrences that are:

  • inevitable and/or
  • hard to refactor

Member Ignoring Method Unsupported Hardware Acceleration Absence of alternatives

slide-126
SLIDE 126

76% of the instances False positives

126

static

Member Ignoring Method

slide-127
SLIDE 127

127

Gap Simplified rule

Member Ignoring Method

slide-128
SLIDE 128

«When faced with a difficult question, we often answer an easier one instead, usually without noticing the substitution»

128

Daniel Kahneman - Thinking, Fast and Slow

slide-129
SLIDE 129

Inaccurate rules

  • Leaking Inner Class
  • Member Ignoring Method
  • No Low Memory Resolver
  • HashMap Usage
  • UI Overdraw
  • Unsupported Hardware Acceleration
  • Init OnDraw
  • Unsuited Cache Size

129

slide-130
SLIDE 130

Inaccurate rules

  • Leaking Inner Class
  • Member Ignoring Method
  • No Low Memory Resolver
  • HashMap Usage
  • UI Overdraw
  • Unsupported Hardware Acceleration
  • Init OnDraw
  • Unsuited Cache Size

130

slide-131
SLIDE 131

Semi automated process Official documentation Developer blogs & talks Q&A forums Catalog of 30 Android code smells ... performance smells

131

Error-prone Inaccurate Inaccurate

slide-132
SLIDE 132

Understanding mobile code smells

  • 1. Extent ✔
  • 2. Causes:
  • Change history ✔
  • 3. Developers’ perception ✔
  • 4. Reassessment ✔

132

slide-133
SLIDE 133

133

Code smell catalog Impact on performance Understand code smells Refactoring catalog Refactoring tools Detection tools

slide-134
SLIDE 134
  • 1. Patch code smell definitions
  • 2. Change code smell identification process
  • 3. Learn from developers to improve definitions

134

slide-135
SLIDE 135
  • 1. Patch code smell definitions
  • 2. Change code smell identification process
  • 3. Learn from developers to improve definitions

135

slide-136
SLIDE 136

Mistakes are inevitable

136

slide-137
SLIDE 137

Code smell definition Code smell detector Code smell instances Properties extractor Accepted instances Rejected instances Definition tuner

suggests

137

slide-138
SLIDE 138

138

Ignorance & Oversight Mindsets Linters help! Need other tools Flawed definitions Common Mobile code smells

138

slide-139
SLIDE 139

Collaborations

139

  • Université du Québec À Montréal

Professor Naouel Moha ○ Two research visits

slide-140
SLIDE 140

Collaborations

140

  • University of Bordeaux

Professor Xavier Blanc ○ One research visit

slide-141
SLIDE 141

Publications

141

  • Sarra Habchi, Xavier Blanc, and Romain Rouvoy. On adopting linters to deal with

performance concerns in Android apps. In ASE18-Proceedings of the 33rd IEEE/ACM International Conference on Automated Software Engineering, 2018.

  • Sarra Habchi, Naouel Moha, and Romain Rouvoy. The rise of Android code smells: Who

is to blame? In MSR2019-Proceedings of the 16th International Conference on Mining Software Repositories, 2019.

  • Sarra Habchi, Romain Rouvoy, and Naouel Moha. On the survival of Android code

smells in the wild. In MOBILESoft19-Proceedings of the 6th IEEE/ACM International Conference on Mobile Software Engineering and Systems, 2019.

  • Sarra Habchi, Geoffrey Hecht, Romain Rouvoy, and Naouel Moha. Code smells in iOS

apps: How do they compare to Android? In MOBILESoft17-Proceedings of the 4th IEEE/ACM International Conference on Mobile Software Engineering and Systems, 2017.

slide-142
SLIDE 142

Publications (under evaluation)

142

  • Sarra Habchi, Xavier Blanc, and Romain Rouvoy. Android Code Smells: From Birth to

Death and Beyond. In Journal of Systems and Software, 2019.

slide-143
SLIDE 143

143

Ignorance & Oversight Mindsets Linters help! Need other tools Flawed definitions Common Mobile code smells

143

slide-144
SLIDE 144

144

Easy xkcd

slide-145
SLIDE 145

145

slide-146
SLIDE 146

Individual attitudes

The general apathy towards issues of technical debt and software quality can be a factor in technical debt accrual. These attitudes influence individual decisions to create a technical debt, and can also bring about a higher level of carelessness. “if you have a lot of Java developers who are very experienced in java and don’t care about the JavaScript they’re writing, most of the JavaScript is going to wind up being a form of technical debt”

146

slide-147
SLIDE 147

Nested classes

Static Nested Classes:

  • Do not require an instance of the containing class to be constructed
  • May not reference the containing class members without an explicit reference.
  • Have their own lifetime

Inner Nested Classes:

  • Automatically have an implicit reference to the containing instance
  • May access the container's class members without the reference
  • Lifetime is supposed to be no longer than that of the container

147

slide-148
SLIDE 148

Leaking Inner Class

  • The issue occurs when an inner class has been kept alive longer than its

container

  • The only way this can occur is if an object outside of the containing class keeps

a reference to the inner object, without regard to the containing object

148

slide-149
SLIDE 149

General research questions

1. Why are mobile code smells so common? 2. What do developers think about mobile code smells? 3. What are the adequate tools for tackling mobile code smells?

149

slide-150
SLIDE 150

«We developed Uber clones, and all those apps did not require any specific performance from the device»

150

Performance is not important in our case

slide-151
SLIDE 151

Survival regression

  • Aalen’s additive model:

λ(t|x) = b0(t) + b1(t) ∗ x1 + ... + bn(t) ∗ xn

  • λ(t): hazard function [ λ(t) = 1 − S(t) ]
  • xi: covariates (variables)
  • bi(t): regression functions (the variables’ impact)

151

slide-152
SLIDE 152

Variables: project properties

  • Project size

○ #Classes ○ #Commits ○ #Developers

  • Project releases

○ #Releases ○ Cycle

152

slide-153
SLIDE 153

153

Positive coefficient → Good for hazard → Bad for survival → Organisation matters