Bold Refactoring

lesson workflow active workflow/bold-refactoring.md View on GitHub

Bold Refactoring

Rule

When creating shared modules or abstractions, immediately refactor existing code to use them. Don't just add - reduce.

Context

When adding new code that could be shared, or when creating abstractions that should replace existing implementations.

Detection

Observable signals that bold refactoring is needed:

Pattern

When adding shared code, immediately apply it:

# ❌ WRONG: Add shared module, propose future use
1. Create shared workspace module
2. CLI uses new module ✓
3. Server still has duplicated code
4. Comment: "Server CAN import from workspace"
5. PR: +1,660 -0 (all additions)

# ✅ CORRECT: Add AND refactor in same PR
1. Create shared workspace module
2. CLI uses new module ✓
3. Refactor server to use module ✓
4. PR: +1,693 -132 (net addition but with refactoring)

Before refactoring (duplicated logic inline):

# 200+ lines of duplicated setup, cloning, config merging...
subprocess.run(["git", "clone", ...])
subprocess.run(["git", "submodule", ...])
# ... same logic repeated in multiple places

After refactoring (uses shared module):

from .shared import create_workspace, init_project
# ~100 lines using shared functions

Outcome

Following this pattern:

Anti-pattern symptoms:

Related

Match Keywords

adding new code without refactoring proposing refactoring without doing it shared module created but not used PR adds code without removing old refactor when adding abstraction