Natthawute Sae-Lim, Shinpei Hayashi, Motoshi Saeki

Department of Computer Science
Graduate School of Information Science and Engineering
Tokyo Institute of Technology

INTRODUCTION2Code smell detector
uCode smell detector
A tool that detect code smells by analyzing source coden Suggests refactoring opportunities to developers
nuProblem: Ignoring current context of developer
E.g. “I’m going to implement the XXX feature”
n The results are mixed withn Smells relevant to the context
n Smells irrelevant to the context
n Results do not fit prefactoring phasenRefactoring beforeimplementing feature3

Motivating example
162 LOC
Very large and complex
Original result when applying ArgoUML v4.2 to code smell detector
Rank

Smell

ModuleSeverity

…

…

…

…

8

Intensive Coupling

UmlFactoryMDRImpl.buildNode(Object)

8…

…

…

…

158

Blob Operation

ProjectBrowser.loadProject(File,boolean) 4

…

…

…

ITS

…

Issue #3921

Issue #4019

Reopen last saved
project should be
reopen last project

Save project dialog
should remember
what was loaded

Issues to be solved until RELEASE-v2.04

Goal
Original code smell
detection result

Proposed code smell
detection result

Our technique

Smells that are relevant to developers’ context
5

PROPOSED TECHNIQUE

6Developer’s context
uDeveloper’s context = modules to be modified
uIssue-driven software development project
Adopting issue tracking systemn Having list of issues needed to be solved before releasennThis list is used to estimate developer’s context
7

Feature location techniqueuIdentify modules in source code that related to afeature
uFeature location → Change prediction
Change description #3921
The option to automaticallyload the last saved project onstartup of ArgoUML I thinkwould be more useful asreopen last project (ie last
opened project or last savedproject)

Relevant modules

Prob

ArgoParser.getProject()

0.27

FigMessage.FigMessage()

0.26

ProjectBrowser.loadProject(File,boolean)

0.22

ActionSettings.handleSave()

0.10

…

…

Project.getBaseName()

0.04

8

Approach overview
Bug 123
Bug 123
BugWhen123
Whenclick…
When
click…
click…

TraceLab
Change descriptions

Feature location

List of modules

Main()xxx;;

Source code

Code smell detection

Scoring
List of smells
1…
2…
3…

Prioritized smells
9

Approach overview
Bug 123
Bug 123
BugWhen123
Whenclick…
When
click…
click…

TraceLab
Change descriptions

Feature location

List of modules

Main()xxx;;

Source code

Code smell detection

Scoring
List of smells
1…
2…
3…

Prioritized smells
10Preparing change descriptions
Issue #3921

ITS…

Reopen last saved
should be reopen
lastIssue #4019
Save project dialog
should remember
what was loaded
Issues to be solved until RELEASE-v2.0
11

Approach overview
Bug 123
Bug 123
BugWhen123
Whenclick…
Whenclick…
click…

TraceLab
Change descriptions

Feature location

List of modules

Main()xxx;;

Source code

Code smell detection

Scoring
List of smells
1…
2…
3…

Prioritized smells
12Applying feature location techniqueuObtaining relevant sets of modules
Change description #3921

Relevant modules

Change description #4019
The save project dialog
assumes you want to save as
the filename of the last
project you saved rather thanthe last project you loaded.

ArgoParser.getProject()

0.27

ProjectBrowser.loadProject(File,boolean)

0.23

ActionSettings.handleSave()

0.10

…

…

Project.getBaseName()

0.04

…

The option to automaticallyload the last saved project onstartup of ArgoUML I thinkwould be more useful asreopen last project (ie lastopened project or last savedproject)

Prob

Relevant modules

Prob

ConfigurationHandler.saveDefault()

0.36

ProjectBrowser.loadProject(File,boolean)

0.22

CheckMain.getTestModel(String)

0.15

…

…

UMLToDoItem.select()

0.03
13

Approach overview
Bug 123
Bug 123
BugWhen123
Whenclick…
When
click…
click…

TraceLab
Change descriptions

Feature location

List of modules

Main()xxx;;

Source code

Code smell detection

Scoring
List of smells
1…
2…
3…

Prioritized smells
14

Code smell detection result
Code smell detection result
Smell…

Level
Class

Blob
MethodOperation…

Module…

Severity…

ProjectBrowser.loadProject(File,boolean)

Subsystem …

4…

15

Approach overview
Bug 123
Bug 123
BugWhen123
Whenclick…
Whenclick…
click…

TraceLab
Change descriptions

Feature location

List of modules

Main()xxx;;

Source code

Code smell detection

Scoring
List of smells
1…
2…
3…

Prioritized smells
16

ScoringuCounting matched module in FL result#3921

Feature location result
Relevant modules

Code smell detection result
Smell…

LevelClass

Module…

Blob
Operation

MethodProjectBrowser.
loadProject(File,boolean)…

Subsystem

…

Score

ArgoParser.getProject()

0.27

ProjectBrowser.loadProject(File,boolean)

0.23

…

…

Project.getBaseName()

0.04

…

2

#4019
Relevant modules

Prob

ConfigurationHandler.saveDefault()

0.36

ProjectBrowser.loadProject(File,boolean)

0.22

…

…

UMLToDoItem.select()

0.03

…

Calculating score
1) Treat every module equally: Score = 22) Use probability as weight: Score = 0.45Prob17

Ordering by score

Original code smell detection result
Rank

Smell

Module

Score

Rank

…

…

…

…

8

Intensive
CouplingbuildNode()

0

…

…

…

158

Blob
Operation

loadProject()

…

…

…

…

Prioritized code smell detection result

…

Smell

Module

Score

…

…

5

Blob
Operation

loadProject()

78

…

…

…

…

…

78

231

Intensive
CouplingbuildNode()

0

…

…

…

…

…

18

PRELIMINARY EVALUATION

19

Evaluation questionsuEQ 1: Does our technique place relevant smells inthe higher rank?
uEQ 2: Does our technique applicable to every
smell level?
uEQ 3: Which weighting scheme is better?
n Treating every smell equallyn Using the probability value from FL result

20Subjects
uUse Dit et al.’s Feature location benchmark datajEdit[176 KLOC]

4.2

Bug 123
Whenclick…

387 smells

ArgoUML[273 KLOC]

0.22
404 smells

Bug 123
Whenclick…

Bug 123
Whenclick…

4.3

150 Issues

Bug 123
Whenclick…

Bug 123
Whenclick…

Bug 123
Whenclick…

0.24

91 Issues

21

Evaluation metricuAverage precision
Metric for evaluating the quality of ranking documents
n Relevant documents in higher rank contribute more value
than the ones in lower rankn

uCalculate average precision for:
Severity

ScoreVS.

Ourapproach

ReorderuGold setn

Smells occurring in the modules actually modified during
two releases
22

EQ 1: Are relevant smells in higher rank ?
1
0.78

Average precision

0.8

0.69

0.6
0.4

0.32

0.29

0.2
0jEditBaseline

ArgoUML

Result from our approach (weight equally)uYes, according to the average precision value23

EQ 2: Applicable to every smell level?
jEdit

ArgoUML
0.95

Average precision

10.8

0.64

0.99

0.89

0.7
0.61

0.58

0.6

0.54

0.4
0.4
0.2

0.19

0.15 0.110Method

ClassSubsystem

MethodClassSubsystem

uOur technique is more appropriate with thecoarse-grained level code smells24

EQ 3 : Weight equally or use probability ?
Average precision

10.8

0.78

0.75

0.69

0.71

0.6
0.4
0.2
0jEditWeight equally

ArgoUMLUse probabilityu No significant differenceu Focus on weighting every smells equallyn Simplicity
n Availability of ‘Probability’ value from FL technique25

Evaluation QuestionsuEQ 1: Are relevant smells in higher rank ?
n Yes
uEQ 2: Applicable to every smell level?
n More appropriate with the coarse-grained leveluEQ 3 : Weight equally or use probability ?
n No difference
uOur approach is potentially effective, but moreinvestigation is needed26

RELATED WORK

27

Related workuUsing context of developer for detecting smell
Hayashi et al. [13]n Liu et al. [14]n Supporting postfactoring phasenuReducing the number of code smell result
Komatsuda et al. [15]n Specifying relevant smell by inserting dummy coden Fontana et al. [16]n Applying strong and weak filter
n Limited to specific type of smellsn[13] S. Hayashi, M. Saeki, and M. Kurihara, “Supporting refactoring activities using histories of program modification”,IEICE2006[14] H. Liu, X. Guo, and W. Shao, “Monitor-based instant software refactoring”, TSE2013[15] T. Komatsuda, S. Hayashi, and M. Saeki, “Supporting prefactoring using feature location results”,IEICE2012[16] F.A. Fontana, V. Ferme, and M. Zanoni, “Filtering code smells detection results”, ICSE2015
28

FUTURE WORK & CONCLUSION

29

Future workuTo conduct case studies to confirm that relevant
code smells are useful to developers
uTo consider other factors
The severity of smells
n The cost needed to fix the smells
n The importance of the issuen30

Conclusion

31