As software becomes essential to almost every aspect of modern life, its environmental impact is increasingly important. While Green IT discussions often focus on data centers, hardware, and electricity consumption, software itself also plays a role. Poorly designed or inefficient code can increase execution time, resource consumption, and ultimately energy use. One important indicator of poor software design is the presence of code smells, patterns in source code that may signal deeper maintainability, performance, or design problems. Our research explores how machine learning can help automatically detect these code smells as a step toward more sustainable software development.

In our paper1, we proposed a supervised machine-learning approach called iCS-EFS. The key idea is to combine ensemble learning with feature-subspace analysis to improve the identification of code smells directly from Java source code. Instead of relying entirely on manual inspection or a single machine-learning model, by training complementary models on different subsets of software metrics, iCS-EFS captures several perspectives on the structural characteristics associated with code smells. We also developed a demonstrator that can analyse Java source code provided through a GitHub source URL, making the approach easier to experiment with in practical scenarios.
We evaluated the approach on several common Java code smells, including Long Method, Feature Envy, God Class, Data Class, Switch Statements, and Long Parameter List. Across the evaluated Java code-smell datasets, iCS-EFS achieved accuracies ranging from 93.98% to 98.81%. The complete experimental protocol and comparative results are reported in our paper. These results indicate that machine-learning-based approaches can support automated code-smell detection. Further evaluation in real development environments would be required to quantify their effect on developers’ efforts.
But detecting a code smell is only the beginning. The larger research question is: Can improving code quality also contribute to greener software? Previous research has investigated relationships between code smells, refactoring, and energy consumption. Our work therefore represents one step toward connecting software quality, machine learning, and Green IT. By automatically identifying problematic code, such systems could eventually support developers in deciding where refactoring may have the greatest potential impact, not only on maintainability and readability, but also on computational efficiency and energy consumption.
The current work focuses on detecting code smells. Building on this foundation, our future research will investigate how AI-based tools can recommend and validate refactorings and assess their measurable environmental effects. However, detecting a code smell does not in itself demonstrate an environmental benefit. The next research step is therefore to determine whether refactoring the detected code smells produces measurable reductions in execution time, resource use, or energy consumption while preserving the software’s functional behaviour.