simplify

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

/simplify

/simplify

Refactor and clean up code after tests pass.
测试通过后重构并清理代码。

Usage

使用方法

/simplify
/simplify src/openenv/core/client.py
/simplify
/simplify src/openenv/core/client.py

When to Use

适用场景

  • After
    /implement
    makes tests pass
  • When code is correct but could be cleaner
  • Before creating a PR (optional polish step)
  • /implement
    使测试通过之后
  • 代码逻辑正确但可以更简洁时
  • 创建PR之前(可选的优化步骤)

When NOT to Use

不适用场景

  • Tests are failing (fix tests first)
  • You want to add new functionality (use
    /write-tests
    first)
  • Code is already clean and simple
  • 测试失败时(先修复测试)
  • 你想要添加新功能时(先使用
    /write-tests
  • 代码已经简洁明了时

What It Does

功能说明

  1. Runs tests to ensure they pass (baseline)
  2. Identifies opportunities for simplification
  3. Refactors while keeping tests green
  4. Runs tests after each change to verify nothing broke
  1. 运行测试确保全部通过(基准验证)
  2. 识别可简化的优化点
  3. 在保持测试通过的前提下进行重构
  4. 每次修改后运行测试,确保没有引入问题

Philosophy

设计理念

This is TDD's third phase: Red → Green → Refactor.
The goal is NOT to add features or change behavior. The goal is to make the code:
  • Easier to read
  • Easier to maintain
  • More consistent with project patterns
  • Less duplicated
这是TDD(测试驱动开发)的第三个阶段:红 → 绿 → 重构
目标不是添加功能或改变行为,而是让代码:
  • 更易读
  • 更易维护
  • 与项目模式更一致
  • 减少重复代码

Guidelines

指导原则

Good Simplifications

合理的简化操作

  • Extract helper functions to reduce duplication
  • Rename variables for clarity
  • Remove dead code
  • Simplify complex conditionals
  • Use more Pythonic idioms
  • 提取辅助函数以减少重复
  • 重命名变量提升可读性
  • 删除死代码
  • 简化复杂条件判断
  • 使用更符合Python风格的写法

NOT Simplifications (Avoid)

非简化操作(需避免)

  • Adding new features
  • Changing public APIs
  • "Improving" code that works and is readable
  • Adding abstractions for hypothetical future needs
  • 添加新功能
  • 修改公共API
  • “优化”原本运行正常且可读性良好的代码
  • 为假设性的未来需求添加抽象层

Completion Criteria

完成标准

  1. All tests still pass
  2. Code is cleaner/simpler than before
  3. No new functionality was added
  4. Changes follow project patterns (see PATTERNS.md)
  1. 所有测试仍能通过
  2. 代码比之前更简洁
  3. 未添加任何新功能
  4. 变更符合项目模式(参考PATTERNS.md)

Integration with TDD Workflow

与TDD工作流的集成

/write-tests  →  create failing tests (Red)
/implement    →  make tests pass (Green)
/simplify     →  clean up code (Refactor)
/pre-submit-pr   →  validate before PR
/write-tests  →  创建失败的测试(红阶段)
/implement    →  使测试通过(绿阶段)
/simplify     →  清理代码(重构阶段)
/pre-submit-pr   →  PR提交前验证