Page 61 - SMILESENG
P. 61

Intl. Summer School on Search- and Machine Learning-based Software Engineering
 Automatizing Software Cognitive Complexity Reduction: What is Next?
Rube´n Saborido, Javier Ferrer, Francisco Chicano ITIS Software, University of Ma´laga, Spain Email: rsain@uma.es, jferrer@uma.es, chicano@uma.es
Abstract—As software increases in complexity, developers spend more time fixing bugs or making code work rather than designing or writing new code. Thus, improving software under- standability and maintainability would translate into an economic relief over the total cost of a project. However, reducing the complexity of a piece of code is not straightforward. Recently, we modeled software cognitive complexity reduction as an optimiza- tion problem and we proposed an approach to assist developers on this task. This approach enumerates sequences of Extract Method refactoring operations until a stopping criterion is met. As result, it returns the minimal sequence of Extract Method refactoring operations found that is able to reduce the cognitive complexity of a method to the given threshold. We evaluated our approach over 10 open-source software projects and was able to fix 78% of the 1,050 existing cognitive complexity issues reported by SonarQube. However, we uncover some limitations and interesting open questions that need further discussion and future work.
I. INTRODUCTION
In 2017, a novel cognitive complexity metric has been proposed and integrated in the well-known static code tools SonarCloud1 and SonarQube2, an open-source service and platform, respectively, for continuous inspection of code qual- ity. This cognitive complexity metric, which we refer to as SonarSource Cognitive Complexity (SSCC), has been defined as a measure of how hard the control flow of a method is to understand and maintain [1]. It breaks from the practice of using mathematical models to assess software maintainability. The SSCC is given by a positive number which is increased every time a control flow sentence appear. Their nested levels also contribute to the SSCC of a method. Although SonarQube suggests to keep methods’ cognitive complexity no greater than 15, software developers lack support to reduce the SSCC of their code to this threshold. Recently, we modelled the reduction of the SSCC to a given threshold as an optimization problem where the search space contains all feasible sequences of extract method refactoring opportunities [2]. Here, we summarize this research line and conclude with open questions for future work.
The remainder of this paper is organized as follows. Sec. II introduces the challenge of reducing SSCC of a method. Sec. III summarizes a recently proposed approach to reduce
1 https://www.sonarcloud.org/ 2https://www.sonarqube.org/
methods SSCC. Sec. IV shows the results of the validation of this approach over 10 open-source Java projects. Sec. V concludes with open research gaps and future work.
II. BACKGROUND
The SSCC at method level can be reduced to a threshold
applying Extract Method refactoring operations: extracting
as a new method in the same class sequences of sentences
(i.e., lines of code). However, this task is not straightforward
because (i) more than one Extract Method refactoring could be
needed to reduce the SSCC of a method, (ii) there are Extract
Method refactorings which are not applicable in practice, and
49
(iii) Extract Method refactoring opportunities are bounded by
r = 􏰀n􏰁 = n·(n−1) , where n is the number of sentences of 22
the method. This is the combination of n sentences taken two at a time without repetition. These two sentences determine the beginning and ending of a code extraction. Thus, the main problem developers face is to find sequences of code extractions that reduce the SSCC of the method. Nevertheless, one would need to evaluate all possible sequences of Extract Method operations, totaling up to 2r alternatives.
III. APPROACH
We recently proposed a SSCC reducer approach, consisting in a solver method that takes as input the path to the software project to process and the cognitive complexity threshold (τ). Then, for each method with SSCC greater than τ, it searches for sequences of applicable Extract Method refactoring oper- ations. In order to perform this task, our approach generates the corresponding Abstract Syntax Tree (AST) of the method. Second, it parses the AST and annotates different properties3 in each node. Third, it processes the annotated AST to obtain Extract Method refactoring opportunities. Once the approach identifies Extract Method refactoring opportunities, it checks if the extractions are applicable. This is done with the help of refactoring tools which are able to check pre-conditions, post-conditions, and apply the corresponding operation over the source code.
We have developed a Java SSCC reducer tool as an Eclipse application. This provides the necessary means for generating an Eclipse product that can be run from the operating system
3These are used to compute the SSCC of extracted methods.










































































   59   60   61   62   63