ChatGPT Prompts for Programming: 12 for Everyday Code Tasks
12 ChatGPT prompts for programming: explain code, write functions from a spec, port between languages, fix bugs from an error and write tests you can run.

ChatGPT prompts for programming give better code when they state the language and version, paste the real code and error, and ask for tests or a check you can run. The model cannot see your project, so the prompt has to carry the context. Below are 12 prompts for programming tasks you do every week, from explaining code to porting it between languages, plus a worked example that catches a rounding bug in a Python to TypeScript port.
The flagship here is the code translation prompt that ports code between languages, tested: a behavior summary, a construct map, the ported code, behavior differences, tests, the run command and a review checklist.
Understand code
1. Explain unfamiliar code
Explain this [language and version] code [code] for someone who knows [your language]. Go block by block, and point out anything surprising.
2. Trace a value
In this code [code], trace the value of [variable] for input [input], step by step, and show where it changes.
Write and change code
3. Function from a spec
Write a [language and version] function that [behavior]. Inputs [types], output [type], errors [cases]. Include tests for normal, edge and error cases.
4. Port between languages
Port this [source language and version] code [code] to [target language and version]. List every construct that behaves differently, then give the port and tests that run the same cases.
5. Small refactor
Refactor this function [code] for readability without changing behavior. Show the tests that prove nothing changed before showing the new code.
Find and fix problems
6. Bug from an error
Running [command] on [language and version] gives this error [full traceback]. Here is the code [code]. Give the likely cause, the fix, and a test that fails before the fix.
7. Edge case hunt
List inputs that could break this function [code]: empty, huge, negative, Unicode, null. Write a test for each and say which ones fail.
8. Code review
Review this diff [diff] for bugs, security problems and missing tests. Rank findings by severity and quote the line for each.
Tests, tools and learning
9. Tests for existing code
Write [test framework] tests for this function [code] covering each branch. Use expected values you can explain, not values copied from the output.
10. Regex or SQL with examples
Write a [regex flavor or SQL dialect] [pattern or query] that [goal]. Show five inputs that should match or return rows and five that should not.
11. Learn by comparison
I know [language] well and am learning [new language]. Show the five habits from my language that cause bugs in the new one, each with a short example.
12. Flagship: port code between languages
SourceCode [complete code], FromLanguage [language, version], ToLanguage [language, version, runtime], TargetStack [libraries, test runner], MustMatch [behavior and edge cases], StyleRules [naming, errors]. Return a behavior summary, construct map, ported code, behavior differences, tests, run command and review checklist.
Worked example: a bill splitter from Python to TypeScript
In the flagship example, a short Python 3.12 function splits a bill in cents with a tip. A literal port would swap Python's round for Math.round, but Python rounds halves to even and Math.round rounds them up, so a 10 percent tip on 25.25 dollars (252.5 cents) becomes 252 in Python and 253 in a naive port, and every share changes. The prompt's construct map flags it, the port adds a small roundHalfEven helper, and the tests check the exact case: shares of 926, 926 and 925 cents. It also flags that Python's divmod and JavaScript's % disagree on negative numbers, so the port rejects negative totals and asks the reviewer to confirm they never occur. The tests run with node --test on Node.js 24.
Variations
- Whole module: port one file at a time, each with its own tests, and keep the old version running until the outputs match.
- Version upgrade: use the port prompt from Python 3.9 to 3.13 or Java 11 to 21, and ask for deprecated calls.
- Pair programming: ask for hints only, not code, when you are learning.
Tips
- Always state the language and version. Advice for one version can be wrong for another.
- Paste the full error and the exact command you ran.
- Run the tests yourself. Treat model-written expected values as claims to check.
- Never paste secrets, keys or customer data into a prompt.
- PromptDig has no ties to OpenAI or the Node.js project; the bill splitter is an invented example.
Related on PromptDig
Planning something bigger? Start with the ChatGPT prompts for coding projects or the ChatGPT prompts for vibe coding. For specific jobs, see the ChatGPT prompts for debugging, the ChatGPT prompts for code explanation and the ChatGPT prompts for coding interviews. More in the Coding hub, browse all prompts, or share a programming prompt you use.