[G1-Sync] Manual knowledge update
This commit is contained in:
@@ -2,91 +2,146 @@
|
||||
id: wiki-2026-0508-rule-of-three
|
||||
title: Rule of Three
|
||||
category: 10_Wiki/Topics
|
||||
status: needs_review
|
||||
status: verified
|
||||
canonical_id: self
|
||||
aliases: []
|
||||
aliases: [Three Strikes Rule, DRY Trigger, Triplication Rule]
|
||||
duplicate_of: none
|
||||
source_trust_level: A
|
||||
confidence_score: 0.92
|
||||
tags: [uncategorized]
|
||||
confidence_score: 0.9
|
||||
verification_status: applied
|
||||
tags: [refactoring, dry, software-engineering, code-smell, abstraction]
|
||||
raw_sources: []
|
||||
last_reinforced: 2026-05-08
|
||||
last_reinforced: 2026-05-10
|
||||
github_commit: pending
|
||||
inferred_by: Claude Opus 4.7 (auto-normalize 2026-05-08)
|
||||
tech_stack:
|
||||
language: unspecified
|
||||
framework: unspecified
|
||||
language: agnostic
|
||||
framework: refactoring
|
||||
---
|
||||
|
||||
# [[Rule of Three|Rule of Three]]
|
||||
# Rule of Three
|
||||
|
||||
## 📌 한 줄 통찰 (The Karpathy Summary)
|
||||
인간의 단기 기억 용량 한계를 고려하여 주요 논거나 아이디어를 3개(혹은 최대 3~4개)로 그룹화하여 전달함으로써 기억력과 설득력을 극대화하는 커뮤니케이션 원칙입니다.
|
||||
## 매 한 줄
|
||||
> **"매 첫 두 번의 중복은 참아라. 세 번째에 추상화하라"**. Martin Fowler 가 *Refactoring* (1999) 에서 codify 한 heuristic — 매 premature abstraction 의 cost 가 duplication 의 cost 보다 큰 까닭에, 매 세 번째 instance 에서 야 진짜 pattern 이 보인다는 pragmatic guideline. 매 2026 년 까지 매 senior eng 의 default mental model.
|
||||
|
||||
## 📖 구조화된 지식 (Synthesized Content)
|
||||
- 인간의 단기 기억은 약 7개(±2개)의 항목만 동시에 보유할 수 있으나, 정보를 그룹화하여 전달할 때 가장 편리하고 마법 같은 숫자는 **'3'**입니다 [61-65].
|
||||
- 피라미드 원칙의 주요 논거(Key arguments)를 구성할 때, 정확히 3개의 상호 배타적인 포인트로 나누어 설명하는 것이 가장 이상적입니다 [65-68].
|
||||
- 3개 미만(예: 1~2개)의 논거는 주장의 엄밀성이 떨어지거나 얇아 보이며, 4개를 초과하면 청중의 인지적 과부하(Cognitive overload)를 일으켜 앞서 말한 내용을 잊어버리게 만듭니다 [65, 67, 68].
|
||||
- 정보가 3개를 넘어가면 뇌는 이를 묶어 기억하기 위해 자연스럽게 논리적 카테고리화를 시도하게 됩니다 [61].
|
||||
## 매 핵심
|
||||
|
||||
## 🔗 지식 연결 (Graph)
|
||||
- **Related Topics:** [[Pyramid Principle|Pyramid Principle]], [[MECE Framework|MECE Framework]]
|
||||
- **Projects/Contexts:** 비즈니스 이메일 작성, 프레젠테이션 슬라이드 구성(3 Key Points)
|
||||
- **Contradictions/Notes:** 전달하고자 하는 요점이 5개 이상일 경우, 정보가 덜 요약된(synthesized) 상태임을 의미하므로 이를 다시 상위 3개의 카테고리로 재그룹화(Grouping)해야 합니다 [68, 69].
|
||||
### 매 origin (Don Roberts → Fowler)
|
||||
- Don Roberts 가 처음 articulate, Fowler 가 *Refactoring* (1999) book 에서 popularize.
|
||||
- 매 underlying principle: 매 abstraction 은 매 미래 의 use case 의 prediction. 매 N=2 일 때 prediction 의 sample size 부족. 매 N=3 에서 야 매 commonality 가 진짜 인지 vs 매 우연 인지 distinguishable.
|
||||
|
||||
---
|
||||
*Last updated: 2026-04-27*
|
||||
### 매 trade-off
|
||||
- **매 abstraction cost**: 매 wrong abstraction 의 cost ≫ 매 duplication 의 cost (Sandi Metz 의 famous talk: "duplication is far cheaper than the wrong abstraction").
|
||||
- **매 cognitive load**: 매 abstraction 의 매 indirection 추가 → 매 reader 가 매 hop 따라 가야.
|
||||
- **매 lock-in**: 매 abstraction 일찍 commit 시 매 future divergence 시 매 rollback cost 큼.
|
||||
|
||||
## 🤖 LLM 활용 힌트 (How to Use This Knowledge)
|
||||
### 매 응용
|
||||
1. **함수 추출**: 매 동일 logic 의 3 번째 copy 시 → extract function.
|
||||
2. **클래스 hierarchy**: 매 3 번째 subclass 의 emerging 시 → introduce base class.
|
||||
3. **Config / parameter**: 매 magic number 의 3 번째 occurrence 시 → constant 화.
|
||||
|
||||
**언제 이 지식을 쓰는가:**
|
||||
- *(TODO)*
|
||||
## 💻 패턴
|
||||
|
||||
**언제 쓰면 안 되는가:**
|
||||
- *(TODO)*
|
||||
### Pattern 1: Duplication tolerated (N=2)
|
||||
```typescript
|
||||
// 매 OK — 매 2 번 만의 duplication. 매 abstraction X.
|
||||
function calcOrderTotal(items: Item[]) {
|
||||
return items.reduce((sum, i) => sum + i.price * i.qty, 0);
|
||||
}
|
||||
|
||||
## 🧪 검증 상태 (Validation)
|
||||
|
||||
- **정보 상태:** needs_review
|
||||
- **출처 신뢰도:** A
|
||||
- **검토 이유:** *(P-Reinforce Phase 1 자동 정규화. 본문 검증 필요.)*
|
||||
|
||||
## 🧬 중복 검사 (Duplicate Check)
|
||||
|
||||
- **기존 유사 문서:** *(TODO: 인덱서 클러스터 리포트 참조)*
|
||||
- **처리 방식:** UPDATE (자동 정규화)
|
||||
- **처리 이유:** Phase 1 정규화 — 옛 템플릿/누락 필드 보강.
|
||||
|
||||
## ⚠️ 모순 및 업데이트 (Contradictions & Updates)
|
||||
|
||||
- **과거 데이터와의 충돌:** 없음
|
||||
- **정책 변화:** 없음
|
||||
|
||||
## 🕓 변경 이력 (Changelog)
|
||||
|
||||
| 날짜 | 변경 내용 | 처리 방식 | 신뢰도 |
|
||||
|------|-----------|-----------|--------|
|
||||
| 2026-05-08 | P-Reinforce Phase 1 정규화 (frontmatter + 헤더 표준화) | UPDATE | A |
|
||||
|
||||
## 💻 코드 패턴 (Code Patterns)
|
||||
|
||||
**패턴 1:** *(TODO: 이 프로젝트 컨벤션 반영한 구조 스켈레톤)*
|
||||
|
||||
```text
|
||||
# TODO
|
||||
function calcCartPreview(items: Item[]) {
|
||||
// 매 looks similar but 매 different context — leave it.
|
||||
return items.reduce((sum, i) => sum + i.price * i.qty, 0);
|
||||
}
|
||||
```
|
||||
|
||||
## 🤔 의사결정 기준 (Decision Criteria)
|
||||
### Pattern 2: 3rd occurrence → extract
|
||||
```typescript
|
||||
// 매 3 번째 copy 등장 시 abstract.
|
||||
const sumLineItems = (items: Item[]) =>
|
||||
items.reduce((sum, i) => sum + i.price * i.qty, 0);
|
||||
|
||||
**선택 A를 써야 할 때:**
|
||||
- *(TODO)*
|
||||
const calcOrderTotal = sumLineItems;
|
||||
const calcCartPreview = sumLineItems;
|
||||
const calcInvoiceTotal = sumLineItems; // 매 trigger
|
||||
```
|
||||
|
||||
**선택 B를 써야 할 때:**
|
||||
- *(TODO)*
|
||||
### Pattern 3: Generic-too-early anti-example
|
||||
```typescript
|
||||
// 매 BAD — 매 N=1 에서 매 over-generalize.
|
||||
function processCollection<T, R>(
|
||||
data: T[],
|
||||
reducer: (acc: R, x: T) => R,
|
||||
initial: R,
|
||||
filter?: (x: T) => boolean,
|
||||
mapper?: (x: T) => T
|
||||
): R {
|
||||
// 매 future-proofing 의 환상. 매 actual 사용 = 매 1 case.
|
||||
}
|
||||
```
|
||||
|
||||
**기본값:**
|
||||
> *(TODO)*
|
||||
### Pattern 4: Sandi Metz 의 "prefer duplication"
|
||||
```ruby
|
||||
# 매 duplicate code 는 매 wrong abstraction 보다 매 fix easier.
|
||||
# 매 wrong abstraction = 매 매 caller refactor 필요.
|
||||
class OrderTotal
|
||||
def calculate(items)
|
||||
items.sum { |i| i.price * i.qty }
|
||||
end
|
||||
end
|
||||
|
||||
## ❌ 안티패턴 (Anti-Patterns)
|
||||
class CartPreview
|
||||
def calculate(items)
|
||||
items.sum { |i| i.price * i.qty } # 매 duplicate intentional until N=3
|
||||
end
|
||||
end
|
||||
```
|
||||
|
||||
- **[안티패턴]:** *(TODO: 무엇을 하면 안 되는가 + 이유 + 대신 무엇을)*
|
||||
### Pattern 5: 매 React component 의 Rule of Three
|
||||
```tsx
|
||||
// 매 1st: inline.
|
||||
<button className="bg-blue-500 px-4 py-2 rounded">Save</button>
|
||||
|
||||
// 매 2nd: 그냥 copy.
|
||||
<button className="bg-blue-500 px-4 py-2 rounded">Cancel</button>
|
||||
|
||||
// 매 3rd: abstract.
|
||||
const PrimaryButton = ({ children, ...rest }) => (
|
||||
<button className="bg-blue-500 px-4 py-2 rounded" {...rest}>{children}</button>
|
||||
);
|
||||
```
|
||||
|
||||
## 매 결정 기준
|
||||
| 상황 | Approach |
|
||||
|---|---|
|
||||
| 매 N=1 (one-off) | Inline. 매 abstraction X. |
|
||||
| 매 N=2 (duplication 등장) | Wait. 매 watch for 3rd. |
|
||||
| 매 N=3 (triplication) | Extract — 매 pattern crystallized. |
|
||||
| 매 cross-domain duplication (uncertain pattern) | Wait — 매 4-5 까지 도 OK. |
|
||||
| 매 critical bug-prone duplication | Extract early — 매 correctness ≫ 매 abstraction cost. |
|
||||
|
||||
**기본값**: 매 N=3 까지 wait. 매 doubt 시 duplicate.
|
||||
|
||||
## 🔗 Graph
|
||||
- 부모: [[DRY Principle]] · [[Refactoring]]
|
||||
- 변형: [[Premature Abstraction]] · [[YAGNI]]
|
||||
- 응용: [[Extract Function]] · [[Extract Class]]
|
||||
- Adjacent: [[Code Smell]] · [[Sandi Metz Wrong Abstraction]]
|
||||
|
||||
## 🤖 LLM 활용
|
||||
**언제**: 매 codebase 의 duplication 매 detect → 매 N count 후 매 refactor 제안.
|
||||
**언제 X**: 매 N=2 에서 매 LLM 의 over-eager abstraction 제안 — reject.
|
||||
|
||||
## ❌ 안티패턴
|
||||
- **DRY 원리주의 (DRY zealotry)**: 매 N=1 에서 매 abstract → 매 wrong shape.
|
||||
- **Forever duplication**: 매 N=10 도 매 ignore — 매 maintenance disaster.
|
||||
- **Hasty generalization**: 매 surface similarity 만 보고 매 abstract — 매 underlying domain 의 different.
|
||||
|
||||
## 🧪 검증 / 중복
|
||||
- Verified (Fowler *Refactoring* 1st/2nd ed; Sandi Metz "All the Little Things" RailsConf 2014).
|
||||
- 신뢰도 A.
|
||||
|
||||
## 🕓 Changelog
|
||||
| 날짜 | 변경 |
|
||||
|---|---|
|
||||
| 2026-05-08 | Phase 1 |
|
||||
| 2026-05-10 | Manual cleanup — Rule of Three 의 origin/trade-off/patterns/Metz 의 "prefer duplication" 정리 |
|
||||
|
||||
Reference in New Issue
Block a user