arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2601.09873cs.SE
收藏

超越严格规则:评估大型语言模型在代码异味检测中的有效性

Beyond Strict Rules: Assessing the Effectiveness of Large Language Models for Code Smell Detection

Universidade Federal de Minas Gerais(米纳斯吉拉斯联邦大学);Universidade Federal de Ouro Preto(奥罗普雷托联邦大学);University of Ottawa(渥太华大学)

Saymon Souza, Amanda Santana, Eduardo Figueiredo, Igor Muzetti, João Eduardo Montandon, Lionel Briand

AI总结:

本研究评估了四种大型语言模型(DeepSeek-R1、GPT-5 mini、Llama-3.3、Qwen2.5-Code)在30个Java项目中检测九种代码异味的效果,并提出了结合LLM与静态分析工具的检测策略,该策略在五个异味类型上F1分数优于单独使用LLM或工具。

摘要:

代码异味是潜在代码质量问题的征兆,可能影响软件可维护性,从而增加开发成本并影响软件可靠性。大型语言模型(LLM)在支持各种软件工程活动方面显示出卓越的能力,但它们在检测代码异味方面的应用仍未得到充分探索。然而,与静态分析工具的严格规则不同,LLM可以支持灵活且适应性强的检测策略,以适应代码异味的独特属性。本文评估了四种LLM——DeepSeek-R1、GPT-5 mini、Llama-3.3和Qwen2.5-Code——在30个Java项目中检测九种代码异味的有效性。为了进行实证评估,我们创建了一个真实数据集,请76名开发人员手动检查了268个代码异味候选。我们的结果表明,LLM在结构简单的异味(如大型类和方法过长)上表现强劲。然而,我们也观察到不同的LLM和工具在不同代码异味上表现各异。然后,我们提出并评估了一种结合LLM和静态分析工具的检测策略。该策略在九种代码异味中的五种上,F1分数优于单独的LLM和工具。然而,对于复杂的异味,它也会产生更多的误报。因此,我们得出结论,最优策略取决于代码异味检测的主要优先级是召回率还是精确率。

英文摘要:

Code smells are symptoms of potential code quality problems that may affect software maintainability, thus increasing development costs and impacting software reliability. Large language models (LLMs) have shown remarkable capabilities for supporting various software engineering activities, but their use for detecting code smells remains underexplored. However, unlike the rigid rules of static analysis tools, LLMs can support flexible and adaptable detection strategies tailored to the unique properties of code smells. This paper evaluates the effectiveness of four LLMs -- DeepSeek-R1, GPT-5 mini, Llama-3.3, and Qwen2.5-Code -- for detecting nine code smells across 30 Java projects. For the empirical evaluation, we created a ground-truth dataset by asking 76 developers to manually inspect 268 code-smell candidates. Our results indicate that LLMs perform strongly for structurally straightforward smells, such as Large Class and Long Method. However, we also observed that different LLMs and tools fare better for distinct code smells. We then propose and evaluate a detection strategy that combines LLMs and static analysis tools. The proposed strategy outperforms LLMs and tools in five out of nine code smells in terms of F1-Score. However, it also generates more false positives for complex smells. Therefore, we conclude that the optimal strategy depends on whether Recall or Precision is the main priority for code smell detection.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑