You are viewing v1 of 1. Go to the current version · All versions

Explain unfamiliar code in plain language

Understand code you inherited: a layered explanation from the big picture down to the tricky lines.

Change note: Initial version

Prompt

I need to understand some {{language}} code I did not write. My experience level: {{level}}.

What I need it for: {{purpose}}

Code:
{{code}}

Explain it in layers:
1. One-paragraph summary: what this code does and why it likely exists.
2. Walkthrough: go through it in execution order. For each logical block say what it does and why, not just what the syntax means.
3. Hard parts: pick the 2-4 trickiest lines or patterns and explain them with a tiny worked example (concrete input, step-by-step result).
4. Hidden behavior: side effects, global or shared state, implicit assumptions, error paths and performance traps.
5. Smells: anything that looks like a bug or a risk, labeled "confirmed" if it is clearly wrong or "suspicion" if it depends on context I did not show.
6. Questions to ask the author or check in the codebase.

Define any jargon the first time you use it, at the level of someone with my experience. Do not rewrite the code unless I ask. If something depends on code that is not shown, say so instead of guessing.

Variables

  • {{language}}Languageselect

    Options: TypeScript, JavaScript, Python, Go, Java, C#, Rust, Ruby, PHP, Kotlin, Swift, C++

    Default: JavaScript

  • {{level}}My experience levelselect

    Options: Beginner, Intermediate, Experienced but new to this language

    Default: Intermediate

  • {{purpose}}Why I need to understand ittext

    Default: I have to add a feature to it next week

  • {{code}}Codelongrequired

    Paste the code to explain.

Example output

**Summary:** This is a debounced search-as-you-type helper. It waits until the user stops typing for 300 ms, cancels any request still in flight, and only displays results from the latest query.

**Walkthrough**
1. `let timer, controller` keeps state outside the function, so it survives between keystrokes (a closure).
2. Each call clears the pending timer, which restarts the 300 ms wait.
3. When the timer fires, the old `AbortController` is aborted and a new one is created, so slow earlier responses are cancelled.
4. `fetch` receives `controller.signal`; on success the results are rendered.

**Hard part:** `catch (e) { if (e.name !== "AbortError") throw e; }`. Aborting a fetch rejects its promise with an error named AbortError. That is expected here, so it is ignored. Example: typing "ca" then "cat" aborts the "ca" request, which rejects quietly.

**Hidden behavior:** the shared `controller` means two instances of this component would cancel each other.

**Smells:** suspicion: no handling for non-200 responses.

**Ask:** is the 300 ms value tuned for a reason?

Notes

Layered output lets you stop reading when you have enough. Labeling smells as confirmed or suspicion keeps the model from inventing bugs.