Last updated:

Which Prompting Technique Should I Use? An Empirical Investigation of Prompting Techniques for Software Engineering Tasks

E. G. Santana Jr et al.

In collections: AI Evals Prompting AI for coding

Strategies from the report:

  • Decomposition: A strategy of breaking complex engineering problems into smaller, sequential subtasks. It helps models handle software architecture without losing context and logic.

  • Thought Generation: Forcing the model to analyze and describe the business logic before it generates the final code or bug fix. This significantly improves effectiveness on tasks that require intensive reasoning.

  • Self-Criticism: Making the model analyze its own initially generated solution, find errors in it and propose an improved, final version before presenting it to the user.

  • Ensembling (combining answers): Having the AI generate several different approaches to solving one problem and choosing the most optimal one, e.g. in terms of performance or code cleanliness.

Best practices:

  • Matching the technique to the specific task: The report indicates that for tasks requiring complex logic (e.g. bug hunting) "Thought Generation" works best, whereas for template-based tasks (e.g. code formatting, writing tests) example-based "Few-Shot" techniques give much better results.

  • Awareness of time and token costs: Always keep resources in mind. Complicated techniques such as Ensembling or Self-Criticism significantly increase token usage and waiting time for a response, so they should not be used for trivial tasks.

  • Optimizing the linguistic features of the prompt: The authors note a strong correlation between the precision of the language used and the quality of the generated code. Specific technical vocabulary helps steer the model toward the right solution.

What to avoid

  • Using one complicated template for everything (One-size-fits-all): Not every prompt engineering technique works equally well on every programming task. Imposing heavy reasoning techniques on simple problems only lowers efficiency and lengthens working time.

  • Demanding the solution to a huge system all at once: Overly large and complex software engineering requests sent in a single prompt (without using decomposition) drastically increase the risk of "hallucinations" and of generating code that does not work.

  • Ignoring the context around the code: Using Zero-Shot mode (without giving examples or broader context) when editing complicated software projects leads to code that does not integrate with the rest of the related application.

Support this project by buying me a coffee ;)