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

我们达到SOLID了吗?关于通过提示LLM检测设计原则违反情况的实证研究

Are We SOLID Yet? An Empirical Study on Prompting LLMs to Detect Design Principle Violations

Bilkent University, Turkey(巴伊肯大学)

Fatih Pehlivan, Arçin Ülkü Ergüzen, Sahand Moslemi Yengejeh, Mayasah Lami, Anil Koyuncu

AI总结:

针对传统静态分析难检测多语言代码SOLID原则违反的问题,构建含240个示例的数据集,测试4种提示策略下4款LLM的检测能力,发现模型性能有层级、提示策略需适配场景,为AI辅助代码设计分析提供参考。

摘要:

传统静态分析方法难以检测语义层面的设计缺陷,例如违反SOLID原则的问题,这类检测需要对面向对象设计模式与原则有深入理解。现有解决方案通常仅聚焦于SOLID中的单个原则或特定编程语言,在多语言代码库中检测全部五项原则违反情况的能力存在空白。本文提出一种新方法:利用定制化提示工程评估大语言模型(LLM)在多语言场景下检测SOLID原则违反的能力。我们构建了包含CodeLlama、DeepSeekCoder、QwenCoder和GPT-4o Mini四款主流LLM的基准测试,检验它们检测全部五项SOLID原则违反的能力。为开展本次评估,我们构建了一个包含240个人工验证代码示例的全新基准数据集。基于该数据集,我们测试了四种不同的提示策略,这些策略受成熟的零样本、少样本和思维链技术启发,用于系统衡量其对检测准确率的影响。初步结果显示,模型之间存在明显的性能层级,GPT-4o Mini的表现显著优于其他模型,但即便它在处理依赖倒置原则(DIP)这类较难的原则时也存在困难。关键的是,我们发现提示策略的影响极大,但没有任何一种策略是普适最优的:例如,审慎型ENSEMBLE(集成)提示在开放封闭原则(OCP)检测中表现出色,而基于提示的EXAMPLE(示例)提示在DIP违反检测中效果更优。在所有实验中,检测准确率受语言特征影响很大,且会随着代码复杂度的提升而急剧下降。这些初步发现表明,有效的AI驱动设计分析不需要单一的最优模型,而是需要一种定制化方案,为特定设计场景匹配合适的模型与提示,凸显了LLM通过AI辅助代码分析提升代码可维护性的潜力。

英文摘要:

Traditional static analysis methods struggle to detect semantic design flaws, such as violations of the SOLID principles, which require a strong understanding of object-oriented design patterns and principles. Existing solutions typically focus on individual SOLID principles or specific programming languages, leaving a gap in the ability to detect violations across all five principles in multi-language codebases. This paper presents a new approach: a methodology that leverages tailored prompt engineering to assess LLMs on their ability to detect SOLID violations across multiple languages. We present a benchmark of four leading LLMs-CodeLlama, DeepSeekCoder, QwenCoder, and GPT-4o Mini-on their ability to detect violations of all five SOLID principles. For this evaluation, we construct a new benchmark dataset of 240 manually validated code examples. Using this dataset, we test four distinct prompt strategies inspired by established zero-shot, few-shot, and chain-of-thought techniques to systematically measure their impact on detection accuracy. Our emerging results reveal a stark hierarchy among models, with GPT-4o Mini decisively outperforming others, yet even struggles with challenging principles like DIP. Crucially, we show that prompt strategy has a dramatic impact, but no single strategy is universally best; for instance, a deliberative ENSEMBLE prompt excels at OCP detection while a hint-based EXAMPLE prompt is superior for DIP violations. Across all experiments, detection accuracy is heavily influenced by language characteristics and degrades sharply with increasing code complexity. These initial findings demonstrate that effective, AI-driven design analysis requires not a single best model, but a tailored approach that matches the right model and prompt to the specific design context, highlighting the potential of LLMs to support maintainability through AI-assisted code analysis.

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

↑