arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2504.13656cs.SEcs.AI
收藏

提示模式会影响代码质量吗?对ChatGPT生成代码的首次实证评估

Do Prompt Patterns Affect Code Quality? A First Empirical Assessment of ChatGPT-Generated Code

University of Salerno(萨勒诺大学)

Antonio Della Porta, Stefano Lambiase, Fabio Palomba

AI总结:

本文通过Dev-GPT数据集实证评估提示模式对ChatGPT生成代码质量的影响,发现零样本提示最常见,且不同提示模式对代码可维护性、安全性和可靠性无显著影响。

摘要:

大型语言模型(LLMs)已迅速改变软件开发,尤其是在代码生成领域。然而,其性能不一致,易产生幻觉和质量问题,这使程序理解复杂化并阻碍可维护性。研究表明,提示工程——即设计输入以引导LLMs生成相关输出的实践——可能有助于解决这些挑战。在这方面,研究人员引入了提示模式,即旨在指导用户制定请求的结构化模板。然而,提示模式对代码质量的影响尚未得到彻底研究。更好地理解这种关系对于推进我们关于如何有效使用LLMs进行代码生成的集体知识至关重要,从而增强其在当代软件开发中的可理解性。本文使用Dev-GPT数据集,实证研究了提示模式对代码质量(特别是可维护性、安全性和可靠性)的影响。结果显示,零样本提示最常见,其次是带思维链的零样本和少样本提示。对7583个代码文件的质量指标分析显示问题极少,Kruskal-Wallis检验表明模式之间无显著差异,这表明在ChatGPT辅助的代码生成中,提示结构可能不会对这些质量指标产生实质性影响。

英文摘要:

Large Language Models (LLMs) have rapidly transformed software development, especially in code generation. However, their inconsistent performance, prone to hallucinations and quality issues, complicates program comprehension and hinders maintainability. Research indicates that prompt engineering-the practice of designing inputs to direct LLMs toward generating relevant outputs-may help address these challenges. In this regard, researchers have introduced prompt patterns, structured templates intended to guide users in formulating their requests. However, the influence of prompt patterns on code quality has yet to be thoroughly investigated. An improved understanding of this relationship would be essential to advancing our collective knowledge on how to effectively use LLMs for code generation, thereby enhancing their understandability in contemporary software development. This paper empirically investigates the impact of prompt patterns on code quality, specifically maintainability, security, and reliability, using the Dev-GPT dataset. Results show that Zero-Shot prompting is most common, followed by Zero-Shot with Chain-of-Thought and Few-Shot. Analysis of 7583 code files across quality metrics revealed minimal issues, with Kruskal-Wallis tests indicating no significant differences among patterns, suggesting that prompt structure may not substantially impact these quality metrics in ChatGPT-assisted code generation.

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

↑