Large Language Models (LLMs) are nowadays extensively used for various types of software engineering tasks, primarily code generation. Previous research has shown how suitable prompt engineering could help developers in improving their code generation prompts. However, so far, there do not exist specific guidelines driving developers towards writing suitable prompts for code generation. In this work, we derive and evaluate development-specific prompt optimization guidelines. First, we use an iterative, test-driven approach to automatically refine code generation prompts, and we analyze the outcome of this process to identify prompt improvement items that lead to test passes. We use such elements to elicit 10 guidelines for prompt improvement, related to better specifying I/O, pre-post conditions, providing examples, various types of details, or clarifying ambiguities. We conduct an assessment with 50 practitioners, who report their usage of the elicited prompt improvement patterns, as well as their perceived usefulness, which does not always correspond to the actual usage before knowing our guidelines. Our results lead to implications not only for practitioners and educators, but also for those aimed at creating better LLM-aided software development tools.
翻译:大型语言模型(LLMs)当前已广泛应用于各类软件工程任务,其中代码生成是主要应用场景。已有研究表明,恰当的提示工程能够帮助开发者优化其代码生成提示。然而,迄今为止,尚缺乏专门指导开发者编写适用于代码生成任务提示的具体准则。本研究提出并评估了面向开发场景的提示优化指南。首先,我们采用迭代式测试驱动方法自动优化代码生成提示,并通过分析该过程的输出结果,识别出能够通过测试的提示改进要素。基于这些要素,我们归纳出10项提示改进指南,涉及输入输出规范、前置后置条件说明、示例提供、多维度细节描述以及模糊性澄清等方面。我们邀请50名从业者进行评估,收集了他们对于所归纳提示改进模式的使用情况及其感知有用性反馈——这些反馈在了解本指南前与实际使用情况并不完全一致。研究结果不仅对从业者和教育者具有启示意义,也为开发更优质的LLM辅助软件开发工具提供了参考。