Mapping Code Smells and Refactorings Accurately: Insights from an Empirical Study
Code smells indicate underlying quality issues that negatively impact software maintainability. Refactoring is a common way to improve code quality by restructuring it, often removing these code smells. While many recommendations exist on how to refactor code smells, we do not fully understand how developers actually remove code smells in the real world. Our study examines this gap by investigating both implementation and design smells and the refactoring techniques developers use to remove them. We also explore how often code smells are removed using established refactoring techniques. We aim to investigate the evolution of code smells and the impact of applied refactoring techniques. We analyzed 212,664 commits from 87 open-source Java projects using both automated tools and manual review to understand the relationship between code smells and refactoring. Our key findings include: a) Extract method refactoring is most effective at fixing multiple smell types, b) Most applied refactorings don’t actually remove code smells, c) About 95% of removed code smells are `dangling’ i.e, they are removed without a matching refactoring technique, and d) Design smells typically last longer in codebases than implementation smells. This research improves our understanding of code smells and refactoring effectiveness. Our results can help researchers develop better tools and guide software engineers in making their refactoring processes more efficient.