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 폴더 제거.
This commit is contained in:
@@ -0,0 +1,153 @@
|
||||
---
|
||||
id: wiki-2026-0508-리팩토링-원칙
|
||||
title: 리팩토링 원칙
|
||||
category: 10_Wiki/Topics
|
||||
status: verified
|
||||
canonical_id: self
|
||||
aliases: [Refactoring Principles, 리팩토링 가이드라인]
|
||||
duplicate_of: none
|
||||
source_trust_level: A
|
||||
confidence_score: 0.9
|
||||
verification_status: applied
|
||||
tags: [refactoring, code-quality, principles]
|
||||
raw_sources: []
|
||||
last_reinforced: 2026-05-10
|
||||
github_commit: pending
|
||||
tech_stack:
|
||||
language: polyglot
|
||||
framework: ide-tooling
|
||||
---
|
||||
|
||||
# 리팩토링 원칙
|
||||
|
||||
## 매 한 줄
|
||||
> **"매 small step, green test, no behavior change"**. Fowler 의 1999 정의 그대로 — 매 외부 동작 보존, 내부 구조 개선. 2026 에 LLM-assisted refactor 가 boilerplate-level change 를 자동화하지만, 매 design intent 의 보존은 여전히 사람의 책임.
|
||||
|
||||
## 매 핵심
|
||||
|
||||
### 매 3대 원칙
|
||||
- **Behavior preservation**: 매 test suite green 유지. Red 면 commit X.
|
||||
- **Small steps**: 매 1 commit = 1 transformation. revert 가능해야.
|
||||
- **Refactor ≠ Rewrite**: 매 새 feature 추가 X. 매 bug fix X. 매 oranges-to-oranges.
|
||||
|
||||
### 매 Two Hats (Kent Beck)
|
||||
- "Adding feature" hat 또는 "Refactoring" hat — 매 동시 X.
|
||||
- Hat 전환 시 commit boundary.
|
||||
|
||||
### 매 응용
|
||||
1. Pre-feature refactor: 매 새 기능 추가 전에 매 ground 정리.
|
||||
2. Code smell 감지 시 즉시 처리 (Boy Scout Rule).
|
||||
3. PR review 에서 매 reviewer-suggested refactor 는 별도 PR.
|
||||
|
||||
## 💻 패턴
|
||||
|
||||
### Extract Function
|
||||
```python
|
||||
# Before
|
||||
def process_order(order):
|
||||
if order.total > 100 and order.customer.tier == "gold":
|
||||
order.discount = order.total * 0.1
|
||||
# ... more logic
|
||||
|
||||
# After
|
||||
def process_order(order):
|
||||
if _is_eligible_for_gold_discount(order):
|
||||
order.discount = order.total * 0.1
|
||||
|
||||
def _is_eligible_for_gold_discount(order):
|
||||
return order.total > 100 and order.customer.tier == "gold"
|
||||
```
|
||||
|
||||
### Replace Magic Number
|
||||
```typescript
|
||||
// Before
|
||||
if (user.age >= 18) { ... }
|
||||
|
||||
// After
|
||||
const LEGAL_ADULT_AGE = 18;
|
||||
if (user.age >= LEGAL_ADULT_AGE) { ... }
|
||||
```
|
||||
|
||||
### Replace Conditional with Polymorphism
|
||||
```python
|
||||
# Before
|
||||
def calculate_pay(employee):
|
||||
if employee.type == "salaried":
|
||||
return employee.monthly_salary
|
||||
elif employee.type == "hourly":
|
||||
return employee.hours * employee.rate
|
||||
|
||||
# After
|
||||
class SalariedEmployee:
|
||||
def pay(self): return self.monthly_salary
|
||||
|
||||
class HourlyEmployee:
|
||||
def pay(self): return self.hours * self.rate
|
||||
```
|
||||
|
||||
### Introduce Parameter Object
|
||||
```typescript
|
||||
// Before
|
||||
function createUser(name, email, phone, address, city, country) { ... }
|
||||
|
||||
// After
|
||||
interface UserProfile {
|
||||
name: string; email: string; phone: string;
|
||||
address: string; city: string; country: string;
|
||||
}
|
||||
function createUser(profile: UserProfile) { ... }
|
||||
```
|
||||
|
||||
### Inline Variable
|
||||
```python
|
||||
# Before
|
||||
price_basis = order.quantity * order.item_price
|
||||
return price_basis > 1000
|
||||
|
||||
# After
|
||||
return order.quantity * order.item_price > 1000
|
||||
```
|
||||
|
||||
### LLM-Assisted Rename (Claude Opus 4.7)
|
||||
```bash
|
||||
# claude code refactor --rename "calc" --to "calculateTotal" \
|
||||
# --scope src/ --dry-run
|
||||
# Reviews semantic usages, not just textual replace.
|
||||
```
|
||||
|
||||
## 매 결정 기준
|
||||
| 상황 | Approach |
|
||||
|---|---|
|
||||
| Test 없음 | 매 먼저 characterization test 작성 |
|
||||
| Behavior change 필요 | 매 refactor 아님 — feature work 으로 분리 |
|
||||
| Large class (1000+ lines) | Extract Class 점진적 적용 |
|
||||
| Duplicated code (3+ sites) | Rule of Three — extract |
|
||||
| Legacy code, no tests | Sprout Method / Sprout Class (Feathers) |
|
||||
|
||||
**기본값**: small commit + green test + IDE refactoring tool 사용.
|
||||
|
||||
## 🔗 Graph
|
||||
- 부모: [[Refactoring_Best_Practices|Refactoring]] · [[Code_Quality]]
|
||||
- 변형: [[Red-Green Refactoring]] · [[Scratch Refactoring (스크래치 리팩토링)]]
|
||||
- 응용: [[Code Refactoring]] · [[Predictive_Refactoring]]
|
||||
- Adjacent: [[Boy Scout Rule]] · [[Technical_Debt]]
|
||||
|
||||
## 🤖 LLM 활용
|
||||
**언제**: 매 boilerplate transformation (rename, extract, format), 매 unfamiliar legacy code 의 의도 파악, 매 test scaffolding 자동 생성.
|
||||
**언제 X**: 매 design decision 이 필요한 architectural refactor — 매 LLM 은 local view 만 봄.
|
||||
|
||||
## ❌ 안티패턴
|
||||
- **Refactoring + Feature mix**: 매 PR 비대 + review 불가능.
|
||||
- **Big bang refactor**: 매 2주 stop-the-world refactor — merge conflict 폭탄.
|
||||
- **Test-less refactor**: 매 behavior preservation 증명 불가.
|
||||
- **Cosmetic-only**: 매 readability 개선 없는 style change 만 — review 시간 낭비.
|
||||
|
||||
## 🧪 검증 / 중복
|
||||
- Verified (Fowler, *Refactoring* 2nd ed., 2018; Beck, *Tidy First?* 2024).
|
||||
- 신뢰도 A.
|
||||
|
||||
## 🕓 Changelog
|
||||
| 날짜 | 변경 |
|
||||
|---|---|
|
||||
| 2026-05-08 | Phase 1 |
|
||||
| 2026-05-10 | Manual cleanup — Fowler/Beck 원칙 + 6 patterns + LLM-assisted refactor 추가 |
|
||||
Reference in New Issue
Block a user