ChatGPT for coding: what it does well and where it gets it wrong (with examples to fix)
ChatGPT is good at coding: it writes working code in seconds, explains errors and translates between languages. But it fails in predictable ways: on details and edge cases, with libraries that do not exist, and always in the same confident tone. Here you see where it really helps, where it gets things wrong and how to notice, with examples to fix right on the page.
Where ChatGPT really helps
- The first draft: a function, a page, a repetitive script.
- Explaining code and error messages you do not understand.
- Translating between languages (Python to JavaScript, SQL to pandas).
- Regular expressions, date formats, commands you never remember.
- Writing tests for a function that already exists.
Where it gets things wrong (and why)
ChatGPT generates the most likely code, not verified code. Typical mistakes:
- Edge cases: empty list, zero, missing values, decimals.
- Language traps: shared objects, automatic conversions,
NULLin SQL. - Made-up libraries: a study presented at USENIX Security 2025, on 576,000 code samples generated by 16 models, showed that references to non-existent packages are a systematic phenomenon. A made-up package is also a security risk: someone can register that name and put malicious code in it.
- Old versions: deprecated functions or APIs that changed after its training data.
- Security: unchecked input, queries built by concatenating text, keys written in the code.
Try it: two typical bugs
This AI-generated function builds an article's tag list. Run it and look at the second article:
def add_tag(tag, tags=[]):
tags.append(tag)
return tags
print(add_tag("python"))
print(add_tag("java"))The second article inherits "python" too: the default [] is created only once and shared by every call. The fixed version:
def add_tag(tag, tags=None):
if tags is None:
tags = []
tags.append(tag)
return tags
print(add_tag("python"))
print(add_tag("java"))Second example, in SQL: finding customers with no email. The query looks right but finds no one.
CREATE TABLE customers (name TEXT, email TEXT);
INSERT INTO customers VALUES ('Anna', 'anna@mail.com'), ('Luke', NULL);
SELECT name FROM customers WHERE email = NULL;In SQL NULL means "unknown" and is never equal to anything: you look for it with IS NULL.
CREATE TABLE customers (name TEXT, email TEXT);
INSERT INTO customers VALUES ('Anna', 'anna@mail.com'), ('Luke', NULL);
SELECT name FROM customers WHERE email IS NULL;How to code with ChatGPT without getting burned
- Give context: language, version, libraries you use, an example input and the expected output.
- Ask for tests too, then read them: they must check exactly the cases you need.
- Predict the output before running on a small example: if it does not match, there is a bug.
- Try edge cases: empty, zero, negatives, decimals,
NULL. - Check every library on its official site before installing it.
- Ask for a line-by-line explanation of code you do not understand, and check that it adds up.
FAQ
Can ChatGPT replace a programmer? It writes code fast, but someone has to judge whether it is correct, safe and right for the project.
Can I learn to code with ChatGPT? Yes, as a tutor that explains. Not as a shortcut that does the exercises for you: without the basics you will not spot its mistakes.
ChatGPT, Claude or Copilot? They work in similar ways and fail in the same places: what matters is how well you can check the result.
Want to practise spotting AI mistakes? The Coding with AI path has 30 challenges with real bugs in Python, JavaScript and SQL, to fix in your browser.