Clear and concise code is necessary to ensure maintainability, so it is crucial that the software is as simple as possible to understand, to avoid bugs and, above all, vulnerabilities. There are many ways to enhance software without changing its functionality, considering the extract method refactoring the primary process to reduce the effort required for code comprehension. The cognitive complexity measure employed in this work is the one defined by SonarSource, which is a company that develops well-known applications for static code analysis. This extraction problem can be modeled as a combinatorial optimization problem. The main difficulty arises from the existence of different criteria for evaluating the solutions obtained, requiring the formulation of the code extraction problem as a multi-objective optimization problem using alternative methods. We propose a multi-objective integer linear programming model to obtain a set of solutions that reduce the cognitive complexity of a given piece of code, such as balancing the number of lines of code and its cognitive complexity. In addition, several algorithms have been developed to validate the model. These algorithms have been integrated into a tool that enables the parameterised resolution of the problem of reducing software cognitive complexity.
翻译:清晰简洁的代码是保证可维护性的必要条件,因此软件应尽可能易于理解,以避免缺陷,尤其是安全漏洞。在不改变功能的前提下,可通过多种方式优化软件,其中提取方法重构是降低代码理解成本的主要手段。本研究采用的认知复杂度度量标准由静态代码分析领域知名开发商SonarSource定义。该提取问题可建模为组合优化问题,其主要难点在于存在多种评估解决方案的准则,需要采用替代方法将代码提取问题构建为多目标优化问题。我们提出了一种多目标整数线性规划模型,用于获取能降低给定代码段认知复杂度的解决方案集合,例如平衡代码行数与认知复杂度。此外,本研究开发了多种算法以验证模型有效性,并将这些算法集成至工具中,实现了软件认知复杂度降低问题的参数化求解。