Before you start
- A ChatGPT account (free or paid)
Method 1 Ask for new code
-
Step 1: Set the context
Start with the language, framework and version, e.g. “Python 3.12” or “Laravel 12, PHP 8.4”.
-
Step 2: Describe the goal
Explain what it should do, with example input and expected output, and any constraints (no extra libraries, must be fast, etc.).
-
Step 3: Ask for an explanation
Ask it to explain how the code works and point out edge cases.
I'm using Python 3.12. Write a function that reads a CSV file of orders
(columns: id, date, amount) and returns total sales per month as a dict.
Skip rows with invalid amounts and explain the code. Include 3 unit tests
using pytest.
Method 2 Fix a bug
-
Step 1: Paste the exact error
Copy the full error message or stack trace, not a summary.
-
Step 2: Share the relevant code
Include the function or file where it happens, plus how you call it. Remove secrets first.
-
Step 3: Explain what you expected
Say what should happen and what happens instead.
-
Step 4: Ask for the cause and fix
Ask it to explain the root cause before the fix, so you can judge whether it’s right.
Method 3 Use it well
-
Step 1: Iterate
If the answer doesn’t work, paste the new error and what you tried. Short feedback loops work best.
-
Step 2: Ask for tests and reviews
Ask it to write tests or review your code for bugs, security issues and readability.
-
Step 3: Use Canvas for longer code
In ChatGPT, longer code can be edited side by side in Canvas, making changes easier to follow.
Troubleshooting
It uses functions that don’t exist
Tell it which library versions you use and ask it to use only documented functions. Check the official docs.
Answers get worse in a long chat
Start a new chat with a clear summary of the current code and problem.
Frequently asked questions
Can ChatGPT replace learning to code?
It speeds you up, but you still need to understand the code to spot mistakes and maintain it.
Is code from ChatGPT safe to use commercially?
Generally you can use output you generate, but review licences of any code it may reproduce and your company’s policies.
Summary
Give ChatGPT the language and versions, a clear goal with examples, and the exact error and code for bugs. Ask for explanations and tests, review and run everything yourself, and keep secrets out of prompts.