Files
2nd/10_Wiki/Topic_Programming/Architecture/Scratch Refactoring (스크래치 리팩토링).md
T
Antigravity Agent 9148c358d0 docs(10_Wiki): 위키 전체 재구성 — Topic_* 폴더를 4개 카테고리로 통합 + 대규모 중복 제거
Topic_Agent/Topic_Blog/Topics/Topics_Biz/Topics_Meeting/Topics_Rag의 마크다운 지식 문서를
Topic_General/Topic_Programming/Topic_Graphic/Topic_Business 4개 카테고리로 재분류.

- 중복 제거: frontmatter의 status:duplicate/merged + duplicate_of/redirect_to 필드로
  자기 자신을 중복으로 선언한 리다이렉트 stub 1032개 제거, 완전 동일 내용 파일 472개 제거,
  동일 파일명·다른 내용 충돌 시 더 큰(완전한) 버전만 유지(162개 제거) — 총 1639개 중복 제거.
- 분류: 폴더 단위로 명확한 항목(AI_and_ML/Coding/Architecture 등 → Programming,
  Comfyui/Visual_Effects → Graphic, Topics_Biz/Topics_Meeting/사업 등 → Business,
  Poetic_Blog_Writing/창의성/Game_Design 등 → General)은 폴더 우선순위로,
  나머지 혼재 폴더(Topic_Agent/Topic_Blog/Topics 루트/Thinking & Reasoning/Other/UI_UX_Assets)는
  title/tags 키워드 스코어링으로 파일 단위 분류(불명확한 경우 General로 폴백).
  원본 폴더명은 "From_*" 서브폴더로 보존해 추적 가능성 유지.
- 최종 배치: Programming 2784 / General 1608 / Graphic 285 / Business 249 = 4926개 문서.
- 에이전트 운영 상태(.astra/.agent/.obsidian/sessions/memory/_company/docs/lessons/_shared/src)는
  지식 콘텐츠가 아니므로 재분류 대상에서 제외하고 원위치 유지.
- Topics/Topic_email(상위 보호 폴더 Topic_email과 파일명 100% 중복) 삭제 — 보호 폴더 자체는 미변경.
- 완전히 비게 된 Topic_Agent/Topic_Blog/Topics_Biz/Topics_Rag 폴더 제거.
2026-07-05 00:33:48 +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