← 返回
未分类 中文

Refactoring

Deep refactoring workflow—characterization tests, incremental steps, behavior preservation, design direction, and verification. Use when improving structure...
深度重构工作流——特性测试、渐进式步骤、行为保持、设计方向与验证。用于改进结构时使用。
mike47512 mike47512 来源
未分类 clawhub v1.0.0 1 版本 99832.2 Key: 无需
★ 0
Stars
📥 595
下载
💾 5
安装
1
版本
#latest

概述

Refactoring (Deep Workflow)

Refactoring changes structure, not behavior. Safety comes from small steps, fast feedback, and verification (tests, golden outputs, or controlled manual checks).

When to Offer This Workflow

Trigger conditions:

  • Code is hard to change; duplication; unclear module boundaries
  • Need to prepare an area for a new feature without mixing behavior change
  • Paying down tech debt with management expecting “no user-visible change”

Initial offer:

Use six stages: (1) clarify goal & scope, (2) establish safety net, (3) plan increments, (4) execute with reviewable commits, (5) verify behavior, (6) document & follow-ups). Confirm test coverage and release pressure.


Stage 1: Clarify Goal & Scope

Goal: Why refactor now—reduce coupling, enable feature X, remove dead code, improve naming.

Exit condition: Explicit non-goals (no feature changes in this effort unless separately scoped).


Stage 2: Establish Safety Net

Goal: Prefer characterization tests for legacy; golden outputs for data pipelines; use snapshot tests sparingly.

If tests are weak

  • Approval tests, short exploratory scripts, or pair review with domain expert

Stage 3: Plan Increments

Goal: Small commits, each leaving the codebase working (not necessarily perfect).

Practices

  • Move code, then change behavior in separate steps (Fowler-style when helpful)
  • Separate mechanical renames from logic edits for reviewability

Stage 4: Execute With Reviewable Commits

Goal: Each PR/commit tells a story; avoid thousand-line “cleanup” dumps.


Stage 5: Verify Behavior

Goal: CI green; compare outputs for batch jobs; manual smoke on critical paths when needed.


Stage 6: Document & Follow-Ups

Goal: ADR or short module README for new boundaries; tickets for remaining debt accepted consciously.


Final Review Checklist

  • [ ] Scope and non-goals explicit
  • [ ] Safety net matches risk
  • [ ] Incremental, reviewable steps
  • [ ] Behavior verified
  • [ ] Follow-up debt tracked

Tips for Effective Guidance

  • Keep refactor commits separate from feature commits when possible.
  • If behavior must change, it is not “pure refactoring”—plan as a migration with communication.
  • Under hotfix pressure, minimize refactor scope or defer.

Handling Deviations

  • Strangler refactors: maintain adapters at boundaries until cutover is complete.

版本历史

共 1 个版本

  • v1.0.0 当前
    2026-03-31 05:59 安全 安全

安全检测

腾讯云安全 (Keen)

安全,无风险
查看报告

腾讯云安全 (Sanbu)

安全,无风险
查看报告

🔗 相关推荐

dev-programming

Mcporter

steipete
使用 mcporter CLI 直接列出、配置、认证及调用 MCP 服务器/工具(支持 HTTP 或 stdio),涵盖临时服务器、配置编辑及 CLI/类型生成功能。
★ 195 📥 67,676
design-media

Visual

mike47512
提供平面设计、UI交互、PPT美化及品牌调性升级指引。
★ 0 📥 2,102
dev-programming

Github

steipete
使用 `gh` CLI 与 GitHub 交互,通过 `gh issue`、`gh pr`、`gh run` 和 `gh api` 管理议题、PR、CI 运行及高级查询。
★ 678 📥 327,590