Bachelor Degree Project Do Software Code Smell Checkers Smell Themselves?
Total Page:16
File Type:pdf, Size:1020Kb
Bachelor Degree Project Do Software Code Smell Checkers Smell Themselves? A Self Reflection Author: Amelie Löwe Author: Stefanos Bampovits Supervisor: Francis Palma Semester: VT/HT 2020 Subject: Computer Science Abstract Code smells are defined as poor implementation and coding practices, and as a result decrease the overall quality of a source code. A number of code smell detection tools are available to automatically detect poor implementation choices, i.e., code smells. The detection of code smells is essential in order to improve the quality of the source code. This report aims to evaluate the accuracy and quality of seven different open-source code smell detection tools, with the purpose of establishing their level of trustworthiness. To assess the trustworthiness of a tool, we utilize a controlled experiment in which several versions of each tool are scrutinized using the most recent version of the same tool. In particular, we wanted to verify to what extent the code smell detection tools that reveal code smells in other systems, contain smells themselves. We further study the evolution of code smells in the tools in terms of number, types of code smells and code smell density. Keywords: Code smells, Automatic detection, Code smell density, Refactoring, Best practices. Preface We would like to thank our supervisor Francis Palma for the continuous support, helpful advice and valuable guidance throughout this bachelor thesis process. Furthermore, we would also like to acknowledge all of the cups of coffee we consumed in the past couple of weeks. Without your assistance, this report would not have been possible. Contents 1 Introduction1 1.1 Background.................................1 1.2 Related Work................................2 1.3 Code Smell Definitions...........................2 1.4 Detection Tools Selection..........................3 1.5 Detection Tools...............................4 1.5.1 Current State............................5 1.5.2 Utility Tools............................5 1.6 Problem Formulation............................6 1.7 Terminology and Definitions........................7 1.8 Objectives..................................7 1.9 Research Questions.............................8 1.10 Motivation..................................9 1.11 Scope/Limitation..............................9 1.12 Target group.................................9 1.13 Outline................................... 10 2 Method 11 2.1 Method Description............................. 11 2.2 Project Development............................ 11 2.2.1 Selection Process.......................... 12 2.2.2 Installation Process......................... 12 2.2.3 Execution of Tools......................... 12 2.2.4 Collecting Data........................... 12 2.2.5 Calculating Results......................... 12 2.2.6 Visualization............................ 12 2.3 Reliability And Validity........................... 13 2.4 Ethical Considerations........................... 13 3 Results 14 3.1 Unique Code Smells............................ 14 3.1.1 FindBugs.............................. 14 3.1.2 Checkstyle............................. 15 3.1.3 JDeodorant............................. 15 3.1.4 PMD................................ 16 3.1.5 SonarQube............................. 16 3.1.6 SpotBugs.............................. 17 3.1.7 Summary Of Code Smell Ratios.................. 17 3.2 Code Smell Evolution............................ 18 3.2.1 Quantity of Code Smells...................... 18 3.2.2 Summary of Quantity of Code Smells............... 19 3.2.3 Types of Code Smells....................... 20 3.2.4 Summary of Types of Code Smells................ 23 3.3 Detection Accuracy............................. 24 3.3.1 FindBugs.............................. 24 3.3.2 Checkstyle............................. 25 3.3.3 JDeodorant............................. 25 3.3.4 PMD................................ 26 3.3.5 SonarQube............................. 26 3.3.6 SpotBugs.............................. 27 3.3.7 UCDetector............................. 27 3.3.8 Summary Of The Detection Accuracy............... 27 3.4 Code Smell Density............................. 28 3.4.1 FindBugs.............................. 29 3.4.2 Checkstyle............................. 29 3.4.3 JDeodorant............................. 30 3.4.4 PMD................................ 30 3.4.5 SonarQube............................. 31 3.4.6 SpotBugs.............................. 31 3.4.7 UCDetector............................. 32 3.4.8 Summary Of Code Smell Density................. 32 4 Analysis 33 4.1 Unique Code Smells............................ 33 4.2 Code Smell Evolution............................ 33 4.3 Detection Tools Accuracy.......................... 34 4.4 Code Smell Density............................. 34 5 Discussion 35 6 Conclusion 37 6.1 Future Work................................. 37 References 38 A Appendix 1A 1 Introduction Automatic code smell detection tools have become increasingly popular within software development in the last decade [1]. Code smells decrease the overall maintainability and readability of a system, increase development costs, and make the refactoring process resource-demanding. In addition, manual detection and refactoring is time-consuming and labor-intensive [2]. The definition of a code smell is subjective, however, a code smell is not considered to be a bug but rather an indication of poor design that can in future developments lead to more severe problems if not refactored and improved. There- fore, even if a tool contains code smells in it’s own source code, it does not necessarily contain bugs. Automatic and semi-automatic detection tools claim to solve the aforemen- tioned issues by assessing large projects with minimal effort required by the developer [3]. However, do the code smells detected by the tools exist in the their own code base? By examining the tools and revealing the number of smells they contain, we can deter- mine whether these tools hold up to their own scrutiny in terms of credibility and to what extent. This paper seeks to investigate how well seven open-source code smell detection tools conform to common coding practices. The idea is to execute the tools on their own source code, in order to see whether they themselves contain code smells and, if so, to what degree. The quality and usefulness of the tools are to be determined by the users and developers, as per their own needs. 1.1 Background The term code smell was first introduced in 1999 by Fowler et al. [4]. Code smells are generally used to diagnose symptoms and characteristics in the source code, which tend to indicate poor quality of the software [5]. The exact definition of a code smell is subjective and depends on different factors like programming language, development methodology, and developer. Martin describes code smells as a value system for software craftsmanship [6]. A code smell refers to a symptom that indicates poor design or best practice violation, however, it is not considered to be as severe as a standard bug [3]. By exposing inadequate design structures and violations of basic design principles, these tools allow the developer to have a straightforward approach towards identifying problem areas and improving code quality [7]. Not improving code quality may further lead to erroneous code and larger bugs in the future of a project. To solve the code issues of a project, large refactoring iterations or even reconstruction of the entire code base is required. Code smell detection tools, also known as software analysis tools, are predominantly used to detect programming anomalies and bad practices. However, different tools have varied definitions, thus, as a general rule, code smell detection tools are used to increase the awareness of a developer about the internal quality of the program in development. The detection of code smells can be done manually by a developer or through the use of different code smell detection tools like JDeodorant, PMD, SonarQube, and others. The manual detection of code smells is labor-intensive and error-prone. Thus, code smell detection tools can be used for automatic or semi-automatic detection of code smells and assist the developer in the search for ‘smelly’ entities [1]. 1 1.2 Related Work This report was inspired by a number of different research articles. The first article by Paiva et al. [8] describes how the detection of code smells is a challenge for developers. Furthermore, this article performs an evaluation as well as a comparison on three main code smell detection tools, inFusion, JDeodorant and PMD. Unlike our project, this arti- cle executed a set of tools on a target system called MobileMedia with intent to identify three main code smells, God Class, God Method and Feature Envy. The authors intended to measure the evolution, accuracy and agreement between the three detection tools when run on the same target system detecting the three aforementioned code smells. Another study that inspired our report is by Hamid et al. [9], where the authors chose to execute two detection tools, JDeodorant and InCode on a target system called Xtreme Media Player which is a cross-platform media player. The target code smells for analysis were Feature Envy and God Class. This article focused on executing the tools on different versions of the target system. In addition, they included the use of metrics to determine lines of code, number of packages, number of classes, etc. for each version of the target system, whereas the previous article did