AI-Assisted Coding109 · Module I · Lesson 02 of 5
Article · 12 min

Prompt patterns for code

Specifications, tests, and diffs.

Summary

Certain prompt patterns produce reliably better code output. Providing types, examples, and negative constraints matters more than politeness or length. This lesson is a small catalog of the patterns that work.

Objectives
  • 01List five prompt patterns that consistently improve code output.
  • 02Explain why negative constraints work.
  • 03Rewrite a bad prompt using the patterns.
The Lesson

The patterns

Include the calling context and the expected types. Include one small example of a working case. State negative constraints ('do not use library X'). Ask for tests in the same output. Ask for a rationale for non-obvious choices.

Key Ideas
  • Types and examples beat prose.
  • Negative constraints beat 'please avoid.'