Code Explanation Prompt Builder Guide
Choose a behavior you can trace
The page packages code for another assistant to explain. This tutorial uses an array transformation because each input and output can be checked without relying on a broad description of what the program “probably” does. No code runs in the page’s explanation function.
Step 1: supply the missing input
Before: “Explain map.” After: “const doubled = [2, 4].map(n => n * 2);” The revised example includes source values and the transformation. Paste the statement, select JavaScript, and choose Intermediate to request an explanation that assumes basic programming knowledge.
Step 2: inspect the request
Generate the exact prompt below. Confirm that the fence says javascript and the statement is unchanged. This is the after state of the tool interaction: a structured explanation request. It is not a result from executing the array transformation.
Input and selections
Code: const doubled = [2, 4].map(n => n * 2);
Language: JavaScript
Level: Intermediate
Exact tool output
Please explain this JavaScript code:
```javascript
const doubled = [2, 4].map(n => n * 2);
```
Explain this code assuming I understand basic programming concepts like variables, loops, and functions.Step 3: make your own trace
Before reading an assistant’s answer, trace the callback: 2 multiplied by 2 gives 4; 4 multiplied by 2 gives 8. Your expected array is [4, 8]. This manual reasoning provides a concrete check for the later explanation rather than trusting its confident tone.
Step 4: ask about one uncertainty
After using the prompt elsewhere, ask how the callback result becomes an element of the new array. Compare that explanation with your trace. For code with helper functions, include their relevant definitions before expecting the same level of certainty.
Mistake 1: confusing the label with detection
Selecting Python does not convert JavaScript or validate syntax. It simply changes the language name and fence label, potentially misleading the assistant receiving the prompt.
Mistake 2: treating Advanced as an audit
Advanced asks for complexity and optimization discussion. It does not prove correctness or security. Check any proposed change against expected behavior and your normal tests.
Worked example: explain a small Python total
The Python example includes concrete prices and selects Beginner. The builder surrounds the snippet with a language-labelled code fence and asks for simple analogies. It does not calculate the total or run Python. An explanation obtained elsewhere should distinguish the stored list from the printed sum; use the actual code as the reference when checking that explanation.
Input and selections
code: prices = [12, 8, 5]
print(sum(prices))
language: Python
level: beginner
Exact tool output
Please explain this Python code:
```python
prices = [12, 8, 5]
print(sum(prices))
```
Explain this code as if I am a complete beginner with no programming experience. Use simple analogies and avoid technical jargon.Worked example: request an advanced explanation
For the duplicate-number example, Advanced appends requests for complexity, design patterns, and potential optimizations. Those are topics requested from another assistant, not findings produced by this page. The snippet itself is copied unchanged. Check whether an eventual explanation answers those topics accurately instead of assuming the extra technical vocabulary makes it correct.
Input and selections
code: const unique = [...new Set([2, 2, 5])];
language: JavaScript
level: advanced
Exact tool output
Please explain this JavaScript code:
```javascript
const unique = [...new Set([2, 2, 5])];
```
Provide a technical explanation including time/space complexity, design patterns used, and potential optimizations.Mistake 3: relying on automatic language detection
The selected language supplies both the opening label and the lowercase fence tag. A Python snippet labelled JavaScript stays mismatched; the builder does not correct the selection.
Mistake 4: omitting the relevant caller
A function name alone rarely shows its inputs or surrounding assumptions. Include a small representative call when it matters; the builder cannot retrieve the missing project context.
Mistake 5: nesting fences without inspection
Triple backticks inside the snippet are copied literally and can disrupt the surrounding fence. Inspect the request before pasting it into an assistant that interprets Markdown.
Tips for better results
- Choose the language explicitly and keep the example self-contained.
- Change only the explanation level when comparing the preset instructions.
- Separate expected behavior from observed behavior in your later discussion; this page supplies neither execution results nor a verified diagnosis.