explain

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Explain Code

代码解释

Provide a clear, thorough explanation of the specified code.
对指定代码给出清晰、全面的解释。

Input

输入

The user will provide one of:
  • A file path:
    /explain src/auth/jwt.ts
  • A file path with line range:
    /explain src/auth/jwt.ts:45-80
  • A function/class name:
    /explain parseToken
  • Just
    /explain
    — explain the currently open or most recently discussed file
用户会提供以下内容之一:
  • 文件路径:
    /explain src/auth/jwt.ts
  • 带行范围的文件路径:
    /explain src/auth/jwt.ts:45-80
  • 函数/类名:
    /explain parseToken
  • 仅输入
    /explain
    —— 解释当前打开的或最近讨论的文件

Explanation Structure

解释结构

1. Overview (2-3 sentences)

1. 概述(2-3句话)

What does this code do at a high level? What problem does it solve?
这段代码的高层作用是什么?它解决了什么问题?

2. Key Components

2. 核心组件

Break down the major parts:
undefined
拆分主要组成部分:
undefined

Function: functionName

Function: functionName

Purpose: One sentence description
Parameters:
  • param1
    (type) — what it's for
  • param2
    (type) — what it's for
Returns: What and when
Side effects: Any mutations, API calls, state changes
undefined
Purpose: One sentence description
Parameters:
  • param1
    (type) — what it's for
  • param2
    (type) — what it's for
Returns: What and when
Side effects: Any mutations, API calls, state changes
undefined

3. Control Flow

3. 控制流

Explain the execution path:
  1. First, it does X
  2. Then checks Y
  3. If Y is true, Z happens
  4. Otherwise, W happens
Use a simple flowchart for complex logic:
Input -> Validate -> Transform -> Output
              |
           Error -> Log -> Return null
解释执行路径:
  1. 首先,执行X操作
  2. 然后检查Y条件
  3. 如果Y为真,执行Z
  4. 否则,执行W
复杂逻辑使用简易流程图:
Input -> Validate -> Transform -> Output
              |
           Error -> Log -> Return null

4. Dependencies

4. 依赖

What does this code depend on?
  • External libraries
  • Internal modules
  • Environment variables
  • Database/API connections
这段代码依赖什么?
  • 外部库
  • 内部模块
  • 环境变量
  • 数据库/API连接

5. Gotchas & Edge Cases

5. 注意事项与边界Case

Things that might surprise someone:
  • Non-obvious behavior
  • Edge cases handled (or not handled)
  • Performance considerations
  • Known limitations
可能让使用者感到意外的点:
  • 不明显的行为
  • 已处理(或未处理)的边界情况
  • 性能考量
  • 已知限制

6. Usage Example

6. 使用示例

Show how to use this code:
typescript
// Example usage
const result = functionName(arg1, arg2);
展示如何使用这段代码:
typescript
// Example usage
const result = functionName(arg1, arg2);

Tone

语气要求

  • Assume the reader is a competent developer unfamiliar with this specific code
  • Avoid jargon unless defining it
  • Use "this code" not "the code" for clarity
  • Be concise but complete
  • 假设读者是有能力的开发者,但不熟悉这段特定代码
  • 避免使用行话,除非你会对其进行定义
  • 为清晰起见,使用“这段代码”而非“该代码”
  • 简洁但完整