Prompt Library

Coding Prompts: AI Prompts for Learning, Debugging & Building

AI tools are genuinely useful coding assistants — for debugging, explaining unfamiliar code, writing boilerplate, learning new languages, and getting unstuck. The key is giving the AI enough context about your language, environment, and the specific problem. These prompts are organized around the most common developer use cases.

Who should use these prompts

Beginner developers learning their first language, self-taught coders who hit walls on specific problems, non-developers who need simple scripts for automation, and professionals who want to move faster on routine coding tasks.

Best use cases

Prompt examples

Debug my code

I am getting this error in my [language] code: [paste error message]. Here is the code that triggers it: [paste code]. The code is supposed to [describe intended behavior]. Please: 1) explain what is causing the error in plain language, 2) show the corrected code, 3) explain what you changed and why.

Always paste the actual error message — it is the most valuable diagnostic signal.

Explain this code

Act as a coding instructor. Explain what this [language] code does in plain language, as if explaining to someone who knows basic programming but not this specific pattern. Go line by line or section by section. Identify: what the function or block does overall, any patterns or idioms being used, and anything that might cause bugs or confusion. Code: [paste code].

Write a function

Act as a [language] developer. Write a function that [describe what the function should do]. Input: [describe input parameters and types]. Output: [describe expected return value]. Edge cases to handle: [list any edge cases]. Include a brief docstring and one usage example. Do not use external libraries unless I specify.

The more you specify about inputs, outputs, and edge cases, the better the function will be.

Convert code to another language

Act as an expert in both [source language] and [target language]. Convert this [source language] code to [target language]. Keep the same logic and variable naming conventions where possible. Explain any translation decisions where the languages handle things differently. Source code: [paste].

Write a shell/Python script

Act as a [shell / Python / JavaScript] scripting expert. Write a script that [describe what the script should do]. Input: [describe any input — files, arguments, environment variables]. Output: [describe what the script should produce or print]. Requirements: [any platform constraints, error handling needs, or style preferences]. Include brief comments for any non-obvious steps.

Explain a programming concept

Act as a programming instructor. Explain [concept — e.g. recursion / closures / async/await / list comprehension] in [language]. Use: 1) a plain English explanation (no jargon first), 2) a minimal code example showing the concept in action, 3) a real-world use case where this pattern is the right choice, 4) one common mistake beginners make with this concept.

Refactor for readability

Act as a senior [language] developer doing a code review. Review this code for readability and maintainability — not functionality. Suggest 3–5 specific improvements: better variable names, cleaner structure, simpler logic, or improved comments. Show the refactored version with the changes. Do not change the behavior. Code: [paste].

Write unit tests

Act as a [language] developer focused on testing. Write unit tests for this function: [paste function]. Cover: the expected happy path, at least 2 edge cases, and one error/exception case. Use [testing framework — e.g. pytest / jest / Go testing] if possible. Each test should have a descriptive name that explains what it is testing.

Set up a project scaffold

Act as a [language/framework] developer. Show me the standard project scaffold for a new [type of project — e.g. FastAPI app / React component library / CLI tool in Go]. Include: the recommended directory structure, key config files with minimal boilerplate content, any package manager setup, and one sentence explaining why each folder or file exists.

Code review checklist

Act as a senior developer reviewing a pull request. Review this code for: correctness (does it do what it claims), security (any input validation issues or unsafe patterns), performance (obvious bottlenecks), and readability (naming, structure, comments). Give your feedback as a numbered list of findings, ordered from most to least critical. Code: [paste].

Common mistakes to avoid

How to customize these prompts

Always specify your language, version, and environment at the start of coding prompts. If working in a framework (Django, React, Rails), mention it. If there are library constraints, mention them. The more context, the better the code.

Related resources

Build your own prompts

Use AI Prompt Generator to generate structured prompts tailored to your specific task, tone, and audience.

Open AI Prompt Generator