All questions
How do I prompt for better code generation?
State the environment (language, version, framework), the exact behavior you want, and constraints like complexity or dependencies. Provide an interface or function signature and at least one representative test case. Ask for small, composable functions over monolithic blobs. For refactors, paste the smallest relevant snippet and a goal. Always request a brief rationale and a test to verify behavior.
In practice
If you can’t write a test, you don’t yet know what ‘correct’ means—fix that before prompting.
Where to start
- 1Add a single passing test to every code request.
- 2Limit code prompts to one feature at a time.
- 3Use diffs for refactors rather than full files.
- 4Run generated code in a sandbox and lint it.
code generation promptAI code writingcoding with LLMs