Programming with AI
ENRU
3.7

Template — explain this code

the key request for anyone learning to read

What it is

The most underrated request. It creates nothing, so it feels optional — and in fact it is what turns someone else's code into yours and closes step 4 of the working cycle.

The important part is asking before you accept the code, not after it breaks. Two minutes of explanation saves an hour of debugging a week later.

What it looks like in code

Three levels of question

Prompt
What does this do, in two sentences?

For quick orientation: you opened someone else's file and need to know whether it matters at all.

Prompt
Explain line by line what this function does.
For each line: what happens and why it is needed.

For code you are about to accept into the project.

Prompt
Why is it done this way here? What were the alternatives
and why was this one chosen?

For code that looks odd. Often it turns out the oddity is justified — or that there is no justification and the code can be simplified.

The question that works best of all

Better
What happens if the API returns an empty list?
And if the connection drops halfway through?

"What happens if" tests code for soundness better than asking for an explanation. When explaining, the AI retells the intention; when answering "what if", it has to follow the real path of execution — and it often finds the hole itself.

What to tell the AI

Ask for an explanation at your level

An explanation is useless if it contains as many unfamiliar words as the code did.

Prompt
Explain it assuming I know Python at the level of functions and
dictionaries, but have never used async and don't know what a
decorator is.

This is not embarrassing and not "for beginners" — it saves time. The AI adjusts the explanation and you avoid five follow-up questions.

Ask for an example rather than a definition

An abstract explanation is forgotten; a concrete one is not.

Prompt
Show me an example: what data arrives in this function and what
it returns. Two or three cases, including a failing one.

Explanation as acceptance

Before accepting generated code, one question is worth asking:

Prompt
Name three places in this code where it will break
on unexpected input.

If the AI cannot name a single one, it probably did not check; if it names three, you have a ready-made list to test.

What to look for

The AI explains the intention, not the code. It reads the function names and retells what they ought to do. If a function is called validate_user but validates nothing, the explanation will still say "validates the user". The defence: ask not "what does it do" but "what happens with this input".

An explanation that sounds confident and is wrong. Especially for third-party libraries and rare language constructs. If a decision depends on the explanation, check the documentation.

Too smooth. If the explanation contains not one "this could break here", it is probably a retelling rather than an analysis. Ask about the weak spots outright.

Cheat sheet

  • Ask before you accept the code, not after it breaks.

  • Three levels: in two sentences · line by line · why this way.

  • "What happens if…" works better than "explain".

  • Name your own level and you get an explanation without the padding.

  • Retell it in your own words and ask to be corrected.

  • The AI tends to retell the intention from the names rather than read the code.