Summary

Completed

You learned how to write specifications that give AI assistants, and human developers, enough detail to build the right code:

  • Deconstruct a vague request into smaller pieces by asking what the user does, what goes in, what comes out, and what can go wrong.
  • Specify the inputs, processing, outputs, and error handling for each piece.
  • Define edge cases, such as empty input, zero, negative values, and the wrong type.
  • Add examples that remove the remaining ambiguity and double as test cases.

When a specification is clear, an AI assistant is more likely to generate correct code on the first attempt, and you spend less time correcting it.

Write your first specification

Start with one small function. A good first specification includes:

  • A one-sentence description of what the function does.
  • The inputs with their types, and the output with its meaning.
  • What can go wrong, and how the function responds to each problem.
  • Two or three examples, including at least one edge case.

Specifications are useful beyond AI. They clarify what you're building before you build it, they help teammates understand the code, and their examples become test cases.