返回提示庫

代码解释

A code explanation prompt that forces the model to explain intent, flow, edge cases, and likely risks in plain language.

審校時間: 2026-03-18

Use this when you need a reliable walkthrough of unfamiliar code, including what it does, why it was written this way, and what can go wrong.

Prompt 模板

Explain the following {language} code for a {target_audience}.

What I need:
- A one-paragraph summary of what it does
- A step-by-step walkthrough of the control flow
- Important inputs, outputs, and side effects
- Edge cases or failure modes
- Any design tradeoffs or code smells worth noticing

Code:
```{language}
{code}
```

Keep the explanation grounded in the actual code. Do not invent behavior that is not shown.

正式使用前,請先替換模板變數並補充你的限制條件。

適用場景

  • Understanding inherited code before editing it
  • Preparing onboarding notes for a teammate
  • Reviewing tricky control flow or algorithmic code

期望輸出

  • High-level summary
  • Step-by-step flow explanation
  • Inputs, outputs, and side effects
  • Edge cases and possible smells

可替換變數

language

Language of the snippet

Example: Python

target_audience

Who the explanation is for

Example: mid-level backend engineer

code

The code to analyze

Example: function body, class, or module excerpt

優化建議

  • Set the audience level to control depth and jargon.
  • If the file is long, narrow the code excerpt and ask about one function at a time.
  • Ask for a call-flow diagram if the code is event-driven or asynchronous.

示例用法

Explain a retry helper used in an API client to a mid-level TypeScript engineer.

預期效果

The model gives you a practical walkthrough of the retry loop, backoff behavior, and likely failure points.

參考來源