What are the best prompts for coding help?

Asked yesterday Updated yesterday 36 views

1 Answer


0

AI coding assistants give much better results when prompts include the right context. Here are proven patterns for common programming tasks.

Debugging:
"I am using [language and version] with [framework and version]. This code should [expected behaviour], but instead [actual behaviour]. Here is the code: [code]. Here is the full error message: [error]. Explain the cause first, then give the fix."

Writing new code:
"Write a [language] function that [task]. Inputs: [describe]. Output: [describe]. Constraints: [performance, libraries allowed, style]. Handle these edge cases: [list]. Include comments and 3 example test cases."

Code review:
"Review this code as a senior developer. Check for bugs, security issues, performance problems and readability. List issues by severity, explain each and suggest fixes. Do not rewrite everything; focus on the most important improvements."

Refactoring:
"Refactor this code to be more readable and maintainable without changing behaviour. Keep the same function names and inputs. Explain each change briefly."

Explaining code:
"Explain this code line by line for someone who knows basic [language] but is new to [library or concept]. Then summarise what the whole function does in two sentences."

Writing tests:
"Write unit tests for this function using [test framework]. Cover normal cases, edge cases and error cases. Use clear test names."

Learning:
"I am learning [topic]. Explain it with a simple example, then give me 3 practice exercises of increasing difficulty. Do not give solutions until I ask."

Database queries:
"Here is my table structure: [schema]. Write a [SQL dialect] query to [task]. Explain how it works and suggest any indexes that would help."

Converting code:
"Convert this [language A] code to [language B]. Use idiomatic [language B] style and standard libraries. Note any behaviour differences."

Context that dramatically improves results:

Language, framework and library versions.
The full error message and stack trace.
Related code, such as function definitions and data structures.
What you have already tried.
Your environment, such as operating system or server setup.

Good habits:

Ask for explanations, not just code.
Request small changes rather than complete rewrites.
Test every suggestion.
Never paste secrets such as API keys, passwords or customer data.

For larger projects, coding agents that can read your whole codebase, such as Claude Code or Codex, reduce the need to paste context manually.

Write Your Answer