对比LLM生成代码与人工代码的缺陷,发现前者质量普遍更低。
Investigating The Smells of LLM Generated Code
- 按任务主题和难度分组测试,量化代码异味程度
- 平均异味率高出63.34%,复杂任务更严重
- 适合关注代码质量的开发者和研究者
大型语言模型(LLMs)在代码生成中应用日益广泛,但现有研究多聚焦功能正确性,忽视代码质量。本文提出一种基于场景的评估方法,通过比较LLM生成代码与专业人工代码的代码异味(code smells)来识别质量薄弱场景。测试数据按代码主题和任务复杂度划分,涵盖四种先进LLM:Gemini Pro、ChatGPT、Codex和Falcon。实验结果显示,LLM生成代码异味率显著高于参考代码,平均增加63.34%,其中实现类异味占比73.35%,设计类异味21.42%。具体表现:Falcon异味增幅最低(42.28%),其次是Gemini Pro(62.07%)、ChatGPT(65.05%),Codex最差(84.97%)。复杂任务及面向对象等高级主题下的异味增加更为明显。结论表明,不同任务复杂度和主题下,LLM生成代码质量与人类代码存在显著差异,整体仍逊于人工编写代码。
原文摘要 · Abstract (English)
Context: Large Language Models (LLMs) are increasingly being used to generate program code. Much research has been reported on the functional correctness of generated code, but there is far less on code quality. Objectives: In this study, we propose a scenario-based method of evaluating the quality of LLM-generated code to identify the weakest scenarios in which the quality of LLM generated code should be improved. Methods: The method measures code smells, an important indicator of code quality, and compares them with a baseline formed from reference solutions of professionally written code. The test dataset is divided into various subsets according to the topics of the code and complexity of the coding tasks to represent different scenarios of using LLMs for code generation. We will also present an automated test system for this purpose and report experiments with the Java programs generated in response to prompts given to four state-of-the-art LLMs: Gemini Pro, ChatGPT, Codex, and Falcon. Results: We find that LLM-generated code has a higher incidence of code smells compared to reference solutions. Falcon performed the least badly, with a smell increase of 42.28%, followed by Gemini Pro (62.07%), ChatGPT (65.05%) and finally Codex (84.97%). The average smell increase across all LLMs was 63.34%, comprising 73.35% for implementation smells and 21.42% for design smells. We also found that the increase in code smells is greater for more complex coding tasks and for more advanced topics, such as those involving object-orientated concepts. Conclusion: In terms of code smells, LLM's performances on various coding task complexities and topics are highly correlated to the quality of human written code in the corresponding scenarios. However, the quality of LLM generated code is noticeably poorer than human written code.
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。