Automating Software Cognitive Complexity Reduction through Integer Linear Programming
收藏资源简介:
We introduce an Integer Linear Programming (ILP) formulation for the software cognitive complexity reduction problem. By encoding refactoring decisions as linear constraints, we can use ILP solvers to compute optimal refactoring plans efficiently. We provide an open-source tool to automatically reduce the SonarSource Cognitive Complexity of Java projects. We empirically validate our approach on a dataset of 1,046 highly complex methods from 10 open-source software projects. Experimental evaluation shows that our ILP-driven approach finds optimal solutions for 85% of the analyzed methods with a median execution time of 10 seconds, resolving the equivalent of 37 developer workdays of manual effort in only three days of automated execution. We also validate the proposed approach on a Java project of a software company, reducing the technical debt from 250 minutes to 29 minutes in just 63 seconds. Furthermore, feedback gathered through a structured survey of industrial developers confirms a strong practical preference for the refactored code, demonstrating that exact optimization of cognitive complexity is both practical and scalable. Here we share the experimental data for open-source projects: refactoring cache for all methods with cognitive complexity greater than 15, a CSV summarizing the results for all methods of open-source projects, a docker compose to load SonarQube populated with data to see the analyses of open-source projects.. The industrial project data and survey responses cannot be shared due to confidentiality agreements with the participating company.



