solid
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseClean Code Principles
整洁代码原则
Apply principles as constraints, not dogma. Prefer measurable maintainability over theoretical purity.
将原则作为约束而非教条来应用。优先考虑可衡量的可维护性,而非理论上的纯粹性。
Use This Skill When
何时使用此技能
- Refactoring complex modules with coupling and duplication.
- Reviewing architecture decisions or PR quality.
- Designing reusable TypeScript services/components.
- 重构存在耦合与重复问题的复杂模块时。
- 评审架构决策或PR质量时。
- 设计可复用的TypeScript服务/组件时。
Principles to Apply
需应用的原则
SOLID
SOLID
- SRP: one reason to change per unit.
- OCP: extend behavior without modifying stable core.
- LSP: subtype must preserve contract behavior.
- ISP: small consumer-focused interfaces.
- DIP: depend on abstractions, not concrete details.
- SRP:每个单元仅有一个变更理由。
- OCP:无需修改稳定核心即可扩展行为。
- LSP:子类型必须保留契约行为。
- ISP:面向消费者的小型接口。
- DIP:依赖抽象而非具体实现细节。
Supporting Rules
辅助规则
- DRY: remove duplicated business logic.
- KISS: prefer simple control flow and explicit naming.
- YAGNI: avoid speculative abstractions.
- DRY:移除重复的业务逻辑。
- KISS:偏好简单的控制流与明确的命名。
- YAGNI:避免过度抽象。
Refactor Workflow
重构工作流
- Detect smells:
- large functions/classes
- feature envy
- repeated condition branches
- temporal coupling
- Write/extend tests around current behavior.
- Extract boundaries:
- interfaces
- services
- adapters
- Reduce responsibilities and dependencies.
- Re-run tests and compare behavior.
- 检测代码异味:
- 大型函数/类
- 特性依恋
- 重复的条件分支
- 时序耦合
- 围绕当前行为编写/扩展测试。
- 提取边界:
- 接口
- 服务
- 适配器
- 减少职责与依赖。
- 重新运行测试并对比行为。
Code Review Checklist
代码评审检查清单
- Does this change reduce or increase coupling?
- Are contracts explicit and stable?
- Is duplication reduced meaningfully?
- Are dependencies inverted where needed?
- Is complexity lower than before?
- 此变更会降低还是增加耦合度?
- 契约是否明确且稳定?
- 重复代码是否得到了有意义的减少?
- 必要的地方是否实现了依赖倒置?
- 复杂度是否比之前更低?
Output Requirements for Agent
Agent输出要求
- Identify concrete smells with file-level evidence.
- Recommend smallest safe refactor sequence.
- State tradeoffs and migration risks.
- Provide test strategy for behavior preservation.
- 结合文件级证据识别具体的代码异味。
- 推荐最安全的最小化重构序列。
- 说明权衡点与迁移风险。
- 提供用于保障行为一致性的测试策略。
References
参考资料
- Detailed examples and before/after refactors:
references/guide.md
- 详细示例及重构前后对比:
references/guide.md