CleanGame Gamifying The Identification of Code Smells
CleanGame Gamifying The Identification of Code Smells
ABSTRACT KEYWORDS
Refactoring is the process of transforming the internal structure Refactoring, gamification, code smell, Software Engineering educa-
of existing code without changing its observable behavior. Many tion, post-training reinforcement
studies have shown that refactoring increases program maintain-
ACM Reference Format:
ability and understandability. Due to these benefits, refactoring is
Hoyama Maria dos Santos, Vinicius H. S. Durelli, Maurício Souza, Eduardo
recognized as a best practice in the software development com- Figueiredo, Lucas Timoteo da Silva, and Rafael S. Durelli. 2019. CleanGame:
munity. However, prior to refactoring activities, developers need Gamifying the Identification of Code Smells. In XXXIII Brazilian Symposium
to look for refactoring opportunities, i.e., developers need to be on Software Engineering (SBES 2019), September 23–27, 2019, Salvador, Brazil.
able to identify code smells, which essentially are instances of poor ACM, New York, NY, USA, 10 pages. https://doi.org/10.1145/3350768.3352490
design and ill-considered implementation choices that may hinder
code maintainability and understandability. However, code smell
1 INTRODUCTION
identification is overlooked in the Computer Science curriculum.
Recently, Software Engineering educators have started exploring Many studies involving industrial scale software systems have pro-
gamification, which entails using game elements in non-game con- vided evidence that the lion’s share of software development ex-
texts, to improve instructional outcomes in educational settings. penses can be ascribed to software maintenance. Maintaining soft-
The potential of gamification lies in supporting and motivating ware systems is a challenging and long-standing topic owing mostly
students, enhancing the learning process and its outcomes. We to the fact that modern software systems must cope with chang-
set out to evaluate the extent to which such claim is valid in the ing requirements. As a consequence, developers need to strive to
context of post-training reinforcement. To this end, we devised and keep software systems in a condition that allows for continuous
implemented CleanGame, which is a gamified tool that covers one evolution. This constant need for improving software systems has
important aspect of the refactoring curriculum: code smell iden- spurred a growing interest in refactoring, which is deemed as one
tification. We also carried out an experiment involving eighteen of the main practices to improve the internal structure of evolving
participants to probe into the effectiveness of gamification in the software systems [11]. The key idea underlying refactoring is to
context of post-training reinforcement. We found that, on average, improve the internal structure of existing code without changing
participants managed to identify twice as much code smells during the observable behavior [11], thereby preparing the code for fu-
learning reinforcement with a gamified approach in comparison ture modifications. When performed properly, refactoring activities
to a non-gamified approach. Moreover, we administered a post- improve the design of software, increasing maintainability and un-
experiment attitudinal survey to the participants. According to the derstandability. Accordingly, refactoring is listed as a recommended
results of such survey, most participants showed a positive attitude practice in the Software Engineering (SE) body of knowledge [6].
towards CleanGame. Prior to refactoring activities, developers need to look for code
smells, i.e., particular code structures that when removed through
CCS CONCEPTS refactoring activities lead to more readable, easy-to-understand,
and cheaper-to-modify code. However, the set of skills required to
· Social and professional topics → Software engineering ed- identify code smells is acquired through training and experience.
ucation. Despite the aforementioned benefits, refactoring and code smell
identification skills have been overlooked in the Computer Science
Permission to make digital or hard copies of all or part of this work for personal or
classroom use is granted without fee provided that copies are not made or distributed curriculum. Even though continuous evolution (i.e., maintenance
for profit or commercial advantage and that copies bear this notice and the full citation activities) accounts for more technical and financial resources than
on the first page. Copyrights for components of this work owned by others than ACM software development per se, a major share of a typical under-
must be honored. Abstracting with credit is permitted. To copy otherwise, or republish,
to post on servers or to redistribute to lists, requires prior specific permission and/or a graduate curriculum is dedicated to development activities [16].
fee. Request permissions from permissions@acm.org. Practices as refactorings are often neglected in favor of more con-
SBES 2019, September 23–27, 2019, Salvador, Brazil structive activities such as design and implementation. In effect,
© 2019 Association for Computing Machinery.
ACM ISBN 978-1-4503-7651-8/19/09. . . $15.00 going through code while looking for code smells is a difficult and
https://doi.org/10.1145/3350768.3352490 somewhat boring task.
437
SBES 2019, September 23ś27, 2019, Salvador, Brazil Santos et al.
A recurring challenge in SE education is engaging students in impact and soundness of gamification in supporting and
learning activities that relate to the professional practices of SE. engaging students during code smell identification activities.
Additionally, it is often challenging for SE students to contextualize (3) We administered an attitudinal survey to the experiment
how some concepts and skills will fit into or influence their fu- participants to get an overview of their attitudes towards
ture professional practices. Recently, in hopes of dealing with such CleanGame and the advantages and drawbacks of using a
challenge, the SE education community has turned to innovative gamified approach to code smell identification.
pedagogical strategies such as gamification [2, 22]. Essentially, gam- The participants of our experiments confirmed that playing the
ification entails employing game design elements in a non-game game is fun, and that identifying smells as part of CleanGame
setting. In other words, gamification is centered around generating is more enjoyable than doing so outside the game. On average,
learning experiences that convey feelings and engage students as participants were able to identify approximately twice as much
if they were playing games, but not with entertainment in mind. code smells using CleanGame (4.94) as subjects using an IDE (2.39).
We conjecture that gamification can be used to improve SE educa- Additionally, the best-performing participants were able to correctly
tion. More specifically, we believe that gamification can be used to identify 8 code smells out of 10 using CleanGame.
support and motivate SE students in the development of code smell The remainder of this paper is organized as follows. Section 2
identification skills by turning a difficult and somewhat tedious provides background on code smells and gamification. Section 3 out-
activity (e.g., going over snippets of code) into an engaging experi- lines related work. Section 4 gives a brief description of CleanGame.
ence. There is much potential insight to be gained in exploring how Section 5 details the experiment we carried out to evaluate CleanGame.
SE education can be improved by devising gamification approaches Section 6 discusses the results of the experiment and their impli-
that cover different aspects related to topics that are overlooked cations. The quantitative results of the attitudinal survey are pre-
in academic curricula, e.g., code smell identification concepts and sented in Section 7. Section 8 discusses the threats to validity of the
skills. study. Section 9 presents concluding remarks.
Based on the premise that gamification is well suited to engage
students with code smell identification concepts, specially when 2 BACKGROUND
used as a way to provide students with training follow-up, we set
This section describes the theoretical foundation necessary for
out to explore whether gamification can have a positive impact on
understanding CleanGame (i.e., code smells and gamification).
post-training reinforcement in comparison with a more traditional
approach, which consists in setting up post-training reinforcement
2.1 Code Smells
content manually. Generally, traditional post-training to evaluate
skill-building in activities such as code smell identification entails Code smells, also known as bad-smells or just smells [11], repre-
hands-on tasks that involve perusing source code for code smells. sent symptoms of the presence of poor design or implementation
Usually, in traditional post-training these tasks are supported only choices in the source code, represent one of the most serious forms
by an integrated development environment (IDE), which allows for of technical debt [15]. Fowler et al. [11] described 22 smells and
easier code navigation. The lack of guidelines and elements to keep incorporated them into refactoring strategies to improve design
students engaged make traditional post-training for code smell quality. In addition to the smells proposed by Fowler et al. [11],
identification unwieldy. So a gamified approach can be employed there are many other code smells [7]. Nevertheless, in this paper
to mitigate these problems. To probe into the benefits provided we focus on the following code smells: (i) Large Class: Classes
by a gamified environment over an IDE-driven post-training, we that are trying to do too much often have a large number of in-
developed a tool that supports post-training activities centered stance variables; (ii) Long Method: It is a method that contains
around code smell identification. In the context of our tool, these too many lines of code; (iii) Divergent Change: Happens when
post-training activities follow a gameful design approach, i.e, they a class is often changed in many different ways and for different
leverage gamification elements such as leaderboard and rewarding reasons; (iv) Feature Envy: Happens when a class spends more
badges. To the best of our knowledge, our tool is the first educational time communicating with functions or data in another class than
platform to realize a gamified, post-training reinforcement approach with their own, may occur after fields have moved to a data class;
to code smell identification. To corroborate the benefits of our (v) Shotgun Surgery: Occurs when changing a class entails a lot
gamified approach, we carried out two evaluations: an experiment of small modifications in many different classes as well.
involving 18 participants and an attitudinal survey, which was Please note that, we selected these code smells because they are
conducted after the experiment. The main contributions of our widely used in academic and industrial settings [21].
research are threefold:
2.2 Gamification
(1) We introduce CleanGame: a gamified platform for post- Gamification is a relatively new term that has been used to denote
training reinforcement of code smell identification concepts the use of game elements and game-design techniques in non-
and skills. gaming contexts [8]. Game elements are a set of components that
(2) In keeping with current evidence, we argue that a gamified compose a game [4]. In some studies, game elements are also called
environment is more effective at conveying code smell iden- game attributes [4].
tification skills while keeping students engaged than a more In the context of SE, there has been an increasing interest in
traditional approach to code smell identification (i.e., IDE- using gamification with the goal of increasing engagement and
driven). So we carried out an experiment to probe into the motivation. Researchers and practitioners have started adopting
438
CleanGame: Gamifying the Identification of Code Smells SBES 2019, September 23ś27, 2019, Salvador, Brazil
gamification in several different contexts, such as, gamification of identifying code smells in the source code. The current implementa-
the software development life cycle [9], software process improve- tion of this module is integrated to PMD2 to allow the creation of a
ment initiatives [14], and also in SE education [2, 22]. However, list of code smells identified in Java source code. CleanGame allows
as mentioned, very little attention has been directed towards inte- users not only to access pre-defined quizzes and identification tasks,
grating refactoring and code smell identification concepts into the but also to create their own quizzes and tasks.
Computer Science curriculum. As stated by Fraser [12], some SE
activities are overlooked in academic curricula because emphasis is
placed on more constructive activities such as software design and
implementation.
In summary, gamification can be applied as a strategy to turn
complex or somewhat boring activities into engaging and competi-
tive activities. Thus, there is much potential insight to be gained
in exploring how SE education can be further improved by devel-
oping gamification approaches that cover different aspects related
to topics that are in a way overlooked in academic curricula, e.g.,
refactoring and refatoring-related concepts as code smells.
3 RELATED WORK
The proposal and use of game-related methods is a crescent topic
in SE education [22]. Gamification, specifically, has gained consid-
Figure 1: Smell-related Quiz module of CleanGame.
erable attention lately [3], both in professional and educational
contexts of SE, as a method to increase motivation and engagement
of subjects in the execution of SE activities. Figure 1 presents a screenshot of CleanGame. This figure shows
In the professional context, Dal Sasso et al.[20] and Garcia et al. a quiz question with four possible answers and the user has to
[13] propose frameworks for the gamification of SE activities. The choose the best option. On the right-hand side of Figure 1, we can
first [20] provides a set of basic building blocks to apply gamification see several game elements used in this gamified software tool, such
techniques, supported by a conceptual framework. The later [13] as player status, score, timing, and skip questions. CleanGame also
propose a complete framework for the introduction of gamification presents a ranking of the top-10 best scores in this quiz. Therefore,
in SE environments. the player is able to check in real time his classification in the
In the context of SE education, there are also several proposals of current quiz and how far this score is in relation to the top scores.
using gamification to support varied knowledge areas. Akpolat and The player score in the current questions is penalized in several
Slany [1] use weekly challenges to motivate students on applying situations. For instance, if the player either skips a question or takes
eXtreme Programming practices to their project. The students had too long to answer it, his score in this question is penalized by up
to compete for a “challenge cup” award. Code Defenders [19] uses to the total amount of points assigned to the given question. Code
gamification to create a ludic and competitive approach to promote smell identification tasks also have options that allow players to
software testing using mutation and unit tests. Bell et al. [5] expose ask for help (shown in Figure 2).
students to software testing using a game-like environment, HALO It is worth mentioning that CleanGame is fully integrated with
(Highly Addictive, sociaLly Optimized) SE. the GitHub application programming interface (API). Therefore,
Nonetheless, to the best of our knowledge, there is no study fo- during the creation of a room in the identification module, the user
cusing on the detection of code smells. CodeArena [10], for instance, need to provide an uniform resource locator (URL) of a Java GitHub
uses gamification to motivate refactoring. However, the target users repository. Then, the Java source code is cloned and transformed
are practitioners. We believe that CleanGame is a solid contribution into an abstract syntax tree (AST) in a fully automatic way to create
to the context of game-related approaches to SE education. an oracle of smells-related questions. Three help hints are available:
metrics used to detect this code smell, refactoring aimed to address
4 CLEANGAME this code smell, and short definition of this code smell. Asking for
help also negatively impact on the points the player receives for a
This section proposes and describes CleanGame1 , a gamified soft- question.
ware tool aimed to teach code smell detection. CleanGame is com-
posed of two independent modules: Smell-related Quiz and Code 5 EXPERIMENT SETUP
Smell Identification. The goal of the first module is to allow student
learning or revisiting the main concepts surrounding code smells. We surmise that gamification is well suited to better engage stu-
To achieve this goal, the Smell-related Quiz module presents ques- dents with refatoring-related topics such as code smell identifi-
tions about code smells with multiple-choice answers. The second cation, specially when used as a way to provide students with
module, Code Smell Identification, focuses on practical tasks of training follow-up. Based on this assumption, we set out to explore
whether gamification can have a positive impact on post-training
2 Itis an extensible cross-language static code analyzer. PMD is available at
1 CleanGame is available at https://bit.ly/2W6xClB https://pmd.github.io/
439
SBES 2019, September 23ś27, 2019, Salvador, Brazil Santos et al.
reinforcement in comparison with a more traditional approach, 5.1.1 Experiment Goals. We used the organization proposed by the
which consists in setting up post-training reinforcement content Goal/Question/Metric (GQM) [25] to set the goals of our experiment.
manually. Traditional post-training to evaluate skill-building in ac- Following such goal definition template, the scope of our study can
tivities such as code smell identification entails hands-on tasks that be summarized as outlined below.
involve perusing source code for code smells. Generally, the tasks
in post-training are supported only by an integrated development Analyze our gamified approach
environment (IDE), which allows for easier code navigation [23]. for the purpose of evaluation
The lack of guidelines and elements to keep students engaged make with respect to post-training effectiveness
traditional post-training for code smell identification unwieldy. We from the point of view of the researcher
believe that a gamified approach can be employed to mitigate these in the context of students looking for code smells.
problems. To probe into the benefits provided by a gamified envi-
ronment over an IDE-driven post-training, identification developed
a tool that supports post-training activities centered around code
smell identification. In the context of our tool, these post-training 5.1.2 Hypotheses Formulation. We framed our prediction for RQ1 :
activities follow a gameful design approach, i.e, they leverage gam- our gamified post-training approach is more effective than an IDE-
ification elements such as leaderboard and rewarding badges. driven approach. As mentioned, to answer RQ1 we evaluated the
effectiveness of the post-training approaches in terms of one proxy
measure: amount of correctly identified code smells (CICS). So RQ1
was turned into the following hypotheses:
440
CleanGame: Gamifying the Identification of Code Smells SBES 2019, September 23ś27, 2019, Salvador, Brazil
441
SBES 2019, September 23ś27, 2019, Salvador, Brazil Santos et al.
Table 1: Code smell identification performance of the two experimental groups using CleanGame.
Group 1
Correct Incorrect
Subject Skipped Metric-related Tip Refactoring-related Tip Definition Tip Average Time†
Answers Answers
#1 6 4 0 8 2 0 476
#2 6 4 0 6 4 4 2,593
#3 5 5 0 6 3 0 1,336
#4 5 5 0 9 4 0 640
#5 5 5 0 6 3 3 674
#6 4 6 0 4 4 3 1,601
#7 2 7 1 1 1 0 1,198
#8 1 9 0 3 1 0 1,231
#9 3 7 0 3 2 1 891
Group 2
Correct Incorrect
Subject Skipped Metric-related Tip Refatoring-related Tip Definition Tip Average Time†
Answers Answers
#1 8 2 0 8 4 0 897
#2 7 3 0 1 1 0 1,259
#3 7 3 0 1 0 0 2,349
#4 6 4 0 8 4 0 1,317
#5 6 4 0 9 4 1 993
#6 5 5 0 9 2 0 1,411
#7 5 5 0 8 2 1 1,951
#8 4 6 0 0 0 0 960
#9 4 6 0 1 1 1 943
Descriptive Statistics for both Experimental Groups
Min 1 2 0 0 0 0 476
Max 8 9 1 9 4 4 2,593
Average (Mean) 4.94 5.00 0.05 5.06 2.33 0.78 1,262.22
Standard Dev. 1.76 1.68 0.24 3.30 1.46 1.27 566.10
† Average time is indicated in seconds.
8
8 RQ2 : Do students have a positive attitude towards a game-based
Amount of Correct Answers
2
RQ3 : What are the advantages and drawbacks of a gamified post-
Group 1 Group 2 training approach? - In addition, we set out to investigate the pros
4 Performance using CleanGame
and cons of gamification as a post-training reinforcement approach
8
from the standpoint of students.
Amount of Correct Answers
442
CleanGame: Gamifying the Identification of Code Smells SBES 2019, September 23ś27, 2019, Salvador, Brazil
443
SBES 2019, September 23ś27, 2019, Salvador, Brazil Santos et al.
9
8 Challenge Q10 2 2 4 6 4 1
6
0
5 Q11 2 5 6 2 3
Satisfaction
3 0
Q12 1 4 5 5 3
2 2
1
0 0 Social Interaction Q13 10 2 8 7 1
1 2 3 4 5
Q14 1 2 3 7 5 1
Fun
Difficulty without CleanGame Difficulty with CleanGame
Q15 3 5 6 1 3 0
Focus
Figure 4: Difficulty in performing the code smell identifica-
tion without and with CleanGame. Q16 0 3 7 8 1
Relevance Q17 0 4 7 7 1
Q7 9 1 2 5 1
Q18 0 2 4 6 6 1
Q8 12 3 10 2
Q19 0 3 4 7 4 1
Q9 3 2 6 5 2
Learning
Definetely disagree Disagree Indifferent Agree Definetely agree Perception Q20 2 2 2 6 6 1
Figure 5: Results for survey questions Q7, Q8, and Q9. Q21 2 01 4 11 2
444
CleanGame: Gamifying the Identification of Code Smells SBES 2019, September 23ś27, 2019, Salvador, Brazil
445
SBES 2019, September 23ś27, 2019, Salvador, Brazil Santos et al.
446