refactor

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Refactor

代码重构

When to use

使用场景

  • Simplifying code after behavior already works
  • Removing duplication, dead code, or unnecessary complexity
  • Cleaning up a focused area without changing what it does
  • 在功能已正常运行后简化代码
  • 移除重复代码、死代码或不必要的复杂结构
  • 在不改变功能的前提下清理特定代码区域

Process

流程

  1. Choose the target from
    $ARGUMENTS
    , current changes, or a clearly relevant recent area. If there is still no clear target, ask.
  2. Read the code and its surrounding context before changing it.
  3. Remove dead code, flatten needless indirection, and simplify naming or structure where the behavior stays the same.
  4. Run the relevant tests and build checks.
  1. $ARGUMENTS
    、当前变更或明确相关的近期代码区域中选择重构目标。如果仍无明确目标,请询问。
  2. 在修改前阅读代码及其上下文。
  3. 在保持功能不变的前提下,移除死代码、简化不必要的间接调用,并优化命名或结构。
  4. 运行相关测试和构建检查。

Verification

验证标准

  • Behavior is unchanged
  • The code is simpler or smaller
  • Tests and build checks pass
  • 功能未发生变化
  • 代码更简洁或更精简
  • 测试和构建检查全部通过

Rules

规则

  • Make the smallest safe refactor.
  • Preserve contracts and externally visible behavior.
  • Do not erase failure-path handling in the name of simplification.
  • If the goal is to change behavior, use a different skill.
  • If you are not sure a change is behavior-preserving, skip it.
  • Prefer deleting or simplifying over adding new abstraction.
  • If the code is already clean, say so.
  • 进行最小范围的安全重构。
  • 保留契约和外部可见的行为。
  • 不要以简化为名删除错误路径处理逻辑。
  • 如果目标是改变功能,请使用其他技能。
  • 如果不确定某项变更是否会保持功能不变,请跳过该变更。
  • 优先选择删除或简化,而非添加新的抽象层。
  • 如果代码已经很整洁,请告知。