"매 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 + 매 폐기.
매 응용
매 거대 legacy class 매 진입할 때 매 first-pass 이해.
매 "이 코드 어떻게 동작?" 질문 매 답.
매 진짜 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
functionprocess(order){returnfinalize(validate(normalize(load(order))));}// 매 scratch: 매 inline 펼침 (commit X)
functionprocess(order){constloaded=db.find(order.id);if(!loaded)thrownewError();constnormalized={...loaded,total: loaded.items.reduce((s,i)=>s+i.price,0)};// ... 매 read해서 이해 → 매 throw away
}
매 rename-storm (학습용)
// 매 이름이 모호한 변수/메서드 매 임시 rename → 매 이해 뒤 폐기
classX{f(d){returnd.x.map(v=>v.y);}}// 매 scratch rename
classOrderQuery{extractCustomerIds(order){returnorder.lines.map(l=>l.customerId);}}// 매 이해 완료 → revert
매 type annotation 추가 (JS → TS scratch)
// 매 untyped JS legacy를 매 임시로 type 입혀 흐름 파악
functionprocess(/** @type {Order} */o){/* ... */}// 매 끝나면 폐기 (매 진짜 migration은 별도 task)
매 log-dump trace
// 매 모든 분기에 console.log → 매 실제 path 관찰
functioncalculate(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.