Recent advances in large language models (LLMs) have accelerated their adoption in software engineering contexts. However, concerns persist about the structural quality of the code they produce. In particular, LLMs often replicate poor coding practices, introducing code smells (i.e., patterns that hinder readability, maintainability, or design integrity). Although prior research has examined the detection or repair of smells, we still lack a clear understanding of how and when these issues emerge in generated code. This paper addresses this gap by systematically measuring, explaining and mitigating smell propensity in LLM-generated code. We build on the Propensity Smelly Score (PSC), a probabilistic metric that estimates the likelihood of generating particular smell types, and establish its robustness as a signal of structural quality. Using PSC as an instrument for causal analysis, we identify how generation strategy, model size, model architecture and prompt formulation shape the structural properties of generated code. Our findings show that prompt design and architectural choices play a decisive role in smell propensity and motivate practical mitigation strategies that reduce its occurrence. A user study further demonstrates that PSC helps developers interpret model behavior and assess code quality, providing evidence that smell propensity signals can support human judgement. Taken together, our work lays the groundwork for integrating quality-aware assessments into the evaluation and deployment of LLMs for code.


翻译:近年来,大型语言模型(LLM)的进展加速了其在软件工程领域的应用。然而,人们对其生成代码的结构质量仍存担忧。特别是,LLM常常复制不良的编码实践,引入代码异味(即阻碍可读性、可维护性或设计完整性的模式)。尽管先前研究已探讨了异味的检测或修复,我们仍不清楚这些问题在生成代码中如何及何时出现。本文通过系统性地测量、解释和缓解LLM生成代码中的异味倾向来填补这一空白。我们基于概率性度量指标——异味倾向得分(PSC)——该指标估计生成特定异味类型的可能性,并确立其作为结构质量信号的稳健性。利用PSC作为因果分析的工具,我们识别了生成策略、模型规模、模型架构和提示词表述如何塑造生成代码的结构特性。我们的研究结果表明,提示词设计和架构选择在异味倾向中起决定性作用,并推动了可减少其出现的实用缓解策略。一项用户研究进一步证明,PSC有助于开发者解释模型行为并评估代码质量,为异味倾向信号可支持人类判断提供了证据。综上所述,我们的工作为将质量感知评估整合到代码生成LLM的评估与部署中奠定了基础。

0
下载
关闭预览

相关内容

代码(Code)是专知网的一个重要知识资料文档板块,旨在整理收录论文源代码、复现代码,经典工程代码等,便于用户查阅下载使用。
图机器学习 2.2-2.4 Properties of Networks, Random Graph
图与推荐
10+阅读 · 2020年3月28日
使用 Keras Tuner 调节超参数
TensorFlow
15+阅读 · 2020年2月6日
国家自然科学基金
17+阅读 · 2015年12月31日
国家自然科学基金
46+阅读 · 2015年12月31日
国家自然科学基金
6+阅读 · 2014年12月31日
国家自然科学基金
1+阅读 · 2014年12月31日
VIP会员
相关基金
国家自然科学基金
17+阅读 · 2015年12月31日
国家自然科学基金
46+阅读 · 2015年12月31日
国家自然科学基金
6+阅读 · 2014年12月31日
国家自然科学基金
1+阅读 · 2014年12月31日
Top
微信扫码咨询专知VIP会员