arXiv:2511.13972cs.SEcs.CL2025-11被引 2

混合提示可更稳定控制代码风格,避免过度冗余。

Show and Tell: Prompt Strategies for Style Control in Multi-Turn LLM Code Generation

  • 用指令+示例混合提示控制代码风格。
  • 混合提示初始压缩最强,后续修改最克制。
  • 适合需要简洁代码的开发场景。

语言模型生成的代码虽功能正确,但常过于冗长,包含大量文档和防御性编程,偏离人类编写习惯。目前有两种风格控制方法:基于指令的抽象要求和基于示例的具体示范。核心问题是:当模型在保持高功能准确性的同时扩展初始代码时,风格约束是否依然有效?我们通过配对双轮实验(N=160)验证四种提示策略:模型先完成一个中等难度的Python任务,再在通用改进指令下修订代码。结果表明:混合提示在初始阶段实现最强压缩,并具备最大扩展纪律性;指令提示初始影响显著但扩展控制中等;示例提示初始效果弱且无扩展纪律。这说明初始控制与扩展纪律是独立维度,混合提示在双轮流程中提供最稳定的风格控制。

原文摘要 · Abstract (English)

Language models generate functionally correct code that tends toward excessive verbosity, with elaborate documentation and defensive patterns that diverge from human baselines. Two prompting mechanisms have emerged for stylistic control: instruction based prompts that articulate abstract directives, and example based prompts that provide concrete code demonstrations. The core problem is whether stylistic constraints persist when models enhance initial implementations with additional features while maintaining high functional accuracy. Here we show that instruction-based, example-based, and combined prompts produce distinct patterns of initial control and expansion discipline over one enhancement turn. We manipulated system prompts across four conditions in a paired two-turn protocol where models first generated solutions to an intermediate Python task, then revised their code under general improvement directives, holding the user task fixed (N = 160 paired programs). Combined prompts produced the strongest initial compression and greatest expansion discipline. Instructions showed large initial effects and moderate expansion discipline. Examples showed modest initial effects with no expansion discipline. These results show that initial prompt effectiveness and expansion discipline are separate aspects of prompt design, and that combined approaches provide the most stable stylistic control in this two-turn workflow.

代码生成提示工程风格控制

Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。