Learn
Cheatsheet
AI Coding Prompts
Ready-to-use prompt patterns for common coding tasks.
Code Generation
| Write a [lang] function that takes [input] and returns [output] | Basic generation — always specify types |
| ... handle the case where [edge case] | Append edge case handling to any prompt |
| ... no external libraries | Constrain to stdlib only |
| ... following [pattern] design pattern | Request a specific architecture |
| ... add XML/JSDoc comments | Ask for documentation inline |
Debugging & Errors
| Here is the error: [paste]. Here is the code: [paste]. What is wrong? | Always share both error and code |
| Why does this return [wrong value] instead of [expected]? | Describe the symptom precisely |
| What are potential null reference issues in this code? | Ask for a specific class of bug |
| Walk me through what this code does step by step | Use to understand before fixing |
Refactoring
| Simplify this method without changing its behavior | Safe refactor request |
| Extract [logic] into a separate [class/method/service] | Structural refactor |
| Make this code more readable | General cleanup |
| Replace this loop with a LINQ/stream equivalent | Idiomatic rewrite |
| What design patterns could improve this code? | Architecture advice |
Testing
| Write unit tests for this method covering happy path and edge cases | Comprehensive test generation |
| What inputs would cause this function to fail? | Identify untested scenarios |
| Write a test that verifies [specific behavior] | Targeted test for a requirement |
| Mock [dependency] and test [method] in isolation | Isolation testing guidance |
Code Review
| What are the security risks in this code? | Security-focused review |
| What are potential performance bottlenecks here? | Performance review |
| Does this code follow [language] best practices? | Idiomatic correctness check |
| What edge cases is this code not handling? | Robustness review |
| Explain this code and rate its readability | Comprehension and quality check |
Token-Efficient Communication
| State goal first | Lead with exactly what you want. "Refactor to async/await" beats "I was wondering if maybe..." |
| Include only relevant code | Paste the function that matters — not the entire file. Strip dead imports and unrelated code. |
| Specify constraints upfront | Language, framework, version, and output format — all in the first line, not the last. |
| One question per message | Focused messages get sharper answers and use fewer total tokens. |
| Reference, don't repeat | Say "the getUserById function above" instead of pasting the code block again. |
| Ask for the diff | "Show only the changed lines" on large files — saves tokens on both sides. |
✅ Do's
| Specify the output format | "Return only the SQL, no explanation" eliminates verbose padding |
| Use exact names from your code | UserService.GetAll() is unambiguous — "the method that gets users" is not |
| Show one expected example | A single input/output sample is worth 50 words of description |
| Continue the same thread | The model carries context — no need to re-explain on every follow-up |
| Say what you already tried | Eliminates suggestions you've already ruled out |
| Ask for the diff, not a full rewrite | "Show only the changed lines" on large files — saves tokens on both sides |
❌ Don'ts
| Over-explaining the obvious | Skip "As you know, Python is..." — the model already knows |
| Pasting dead code | Unused variables, commented blocks, and irrelevant imports dilute context |
| Asking about an entire system at once | "Redesign my whole app" yields vague answers — break it into specific questions |
| Quoting the full previous response | Just ask your follow-up directly without repeating the AI's answer back |
| Using emotional framing | "Please try really hard" has no effect — precise constraints do |
| Requesting code AND explanation by default | Ask for explanation only when you need it — skip it when you just need working code |