Files
2nd/10_Wiki/Topics/Architecture/Scratch Refactoring (스크래치 리팩토링).md
T
Antigravity Agent f8b21af4be Wiki cleanup: error-doc removal, dedup merge, link normalization
10_Wiki/Topics 대규모 정리:
- 오류 캡처/미완성 stub 문서 227개 제거
- 교차폴더 중복 43클러스터 병합 (63파일 → redirect)
- 링크명 정규화: 깨진 링크 수정·redirect 직결·개념 매핑 ~2,400건
- 카테고리 MOC 6개 신규 생성
- Graph 섹션 미해결 related-keyword 링크 10,058건 제거

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-20 23:52:15 +09:00

4.4 KiB

id, title, category, status, canonical_id, aliases, duplicate_of, source_trust_level, confidence_score, verification_status, tags, raw_sources, last_reinforced, github_commit, tech_stack
id title category status canonical_id aliases duplicate_of source_trust_level confidence_score verification_status tags raw_sources last_reinforced github_commit tech_stack
wiki-2026-0508-scratch-refactoring-스크래치-리팩토링 Scratch Refactoring (스크래치 리팩토링) 10_Wiki/Topics verified self
Scratch Refactoring
throwaway refactor
exploratory refactoring
none A 0.9 applied
refactoring
technique
learning
2026-05-10 pending
language framework
typescript none

Scratch Refactoring (스크래치 리팩토링)

매 한 줄

"매 throwaway refactor — 매 코드 이해를 위한 도구로서의 리팩토링". Michael Feathers가 Working Effectively with Legacy Code에서 정형화. 매 결과 코드를 commit하지 않고, 매 ugly legacy를 매 자유롭게 변형하며 매 구조를 학습한 뒤 매 throw away.

매 핵심

매 정의

  • 매 commit하지 않는 refactor.
  • 매 목적: 코드 이해 (test 작성 X, 동작 보존 X).
  • 매 끝나면 git checkout ..

매 vs 일반 refactor

  • 일반 refactor: 매 동작 보존 + commit.
  • Scratch refactor: 매 동작 깨져도 OK + 매 폐기.

매 응용

  1. 매 거대 legacy class 매 진입할 때 매 first-pass 이해.
  2. 매 "이 코드 어떻게 동작?" 질문 매 답.
  3. 매 진짜 refactor 의 매 사전 탐색.

💻 패턴

매 brutal extraction (commit X)

# 매 worktree에서 자유롭게 변형
git switch -c scratch/explore-OrderService
# ... 매 method 분리, rename, comment 추가, dead code 삭제 ...
# 매 끝나면
git switch main
git branch -D scratch/explore-OrderService

매 inline-everything (이해용)

// 매 before — 매 6단계 helper chain
function process(order) { return finalize(validate(normalize(load(order)))); }

// 매 scratch: 매 inline 펼침 (commit X)
function process(order) {
  const loaded = db.find(order.id);
  if (!loaded) throw new Error();
  const normalized = { ...loaded, total: loaded.items.reduce((s,i)=>s+i.price, 0) };
  // ... 매 read해서 이해 → 매 throw away
}

매 rename-storm (학습용)

// 매 이름이 모호한 변수/메서드 매 임시 rename → 매 이해 뒤 폐기
class X { f(d) { return d.x.map(v=>v.y); } }
// 매 scratch rename
class OrderQuery { extractCustomerIds(order) { return order.lines.map(l=>l.customerId); } }
// 매 이해 완료 → revert

매 type annotation 추가 (JS → TS scratch)

// 매 untyped JS legacy를 매 임시로 type 입혀 흐름 파악
function process(/** @type {Order} */ o) { /* ... */ }
// 매 끝나면 폐기 (매 진짜 migration은 별도 task)

매 log-dump trace

// 매 모든 분기에 console.log → 매 실제 path 관찰
function calculate(o) {
  console.log("calculate", o);
  if (o.type === "A") { console.log("branch A"); /* ... */ }
  // 매 trace 후 매 모든 log 제거
}

매 AI-assisted scratch (2026)

# 매 Claude Opus 4.7에 매 scratch refactor 부탁
claude "Read src/legacy/OrderService.ts. Inline all helpers, rename obscure vars,
add comments explaining each branch. Goal: human-readable. Don't preserve behavior."
# 매 결과 매 read만 하고 매 discard

매 결정 기준

상황 Approach
매 legacy 매 처음 진입 Scratch refactor 먼저.
매 production fix 중 X — 매 일반 refactor + test.
매 시간 부족 매 scratch도 OK — 매 빠른 이해 우선.
매 팀 onboarding 매 신입 매 scratch refactor 권장.

기본값: 매 unfamiliar legacy → scratch refactor → 이해 → 진짜 refactor.

🔗 Graph

🤖 LLM 활용

언제: 매 거대 legacy 진입, 매 코드 이해가 매 1차 목표일 때. 언제 X: 매 production behavior change, 매 long-term improvement.

안티패턴

  • 매 commit해버림: 매 scratch가 매 production에 매 leak.
  • 매 너무 오래 매 매달림: 매 scratch는 매 hours, 매 days X.
  • 매 test 없이 매 진짜 refactor 시도: 매 scratch 후 매 진짜 refactor에는 매 test 필수.

🧪 검증 / 중복

  • Verified (Feathers, Working Effectively with Legacy Code, 2004).
  • 신뢰도 A.

🕓 Changelog

날짜 변경
2026-05-08 Phase 1
2026-05-10 Manual cleanup — Feathers scratch refactor + AI-assisted variant