Files
2nd/10_Wiki/Topics/Architecture/보이스카우트 규칙 (Boy Scout Rule).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

156 lines
5.1 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
---
id: wiki-2026-0508-보이스카우트-규칙-boy-scout-rule
title: 보이스카우트 규칙 (Boy Scout Rule)
category: 10_Wiki/Topics
status: verified
canonical_id: self
aliases: [Boy Scout Rule, Campsite Rule, Leave It Better, 점진적 개선]
duplicate_of: none
source_trust_level: A
confidence_score: 0.9
verification_status: applied
tags: [clean-code, refactoring, software-craftsmanship, principles]
raw_sources: []
last_reinforced: 2026-05-10
github_commit: pending
tech_stack:
language: language-agnostic
framework: refactoring
---
# 보이스카우트 규칙 (Boy Scout Rule)
## 매 한 줄
> **"매 check in 한 코드 의 check out 한 코드 보다 cleaner 의 leave."**. Robert C. Martin (*Clean Code*, 2008) 의 popularize — 매 boy scout motto "leave the campsite cleaner than you found it" 의 software 의 apply. 2026 modern context 는 매 LLM-assisted refactor (Claude, Cursor) 의 cost 의 dramatic 의 lower — 매 rule 의 practice 의 ever-easier.
## 매 핵심
### 매 핵심 아이디어
- 매 touch 한 file 에 매 small improvement.
- 매 variable rename · dead code 의 delete · 매 magic number 의 const · 매 function 의 split.
- 매 commit 의 scope 의 keep small — 매 unrelated cleanup 의 separate commit.
### 매 왜
- **Entropy 와 fight**: 매 code 의 자연 의 decay — 매 active counter-force 의 필요.
- **Compound interest**: 매 small fix × N developer × M commit = 매 substantial improvement.
- **Cognitive load 의 lower**: 매 next reader 의 효과.
### 매 응용
1. 매 PR 의 작은 cleanup 의 같이 include (그러나 main change 의 separate commit).
2. 매 LLM 의 통한 매 mechanical refactor 의 batch.
3. 매 lint/format 의 pre-commit 의 enforce — 매 baseline 의 raise.
## 💻 패턴
### 매 commit 의 separate (git)
```bash
# Main change
git add src/feature.ts
git commit -m "feat: add export to PDF"
# Boy scout cleanup
git add src/utils.ts # 매 touched file 의 cleanup
git commit -m "refactor: extract date formatter, rename ambiguous vars"
```
### 매 magic number 의 const 의 promote
```typescript
// Before
if (user.failedAttempts > 5) lockout(user);
// After
const MAX_FAILED_LOGIN_ATTEMPTS = 5;
if (user.failedAttempts > MAX_FAILED_LOGIN_ATTEMPTS) lockout(user);
```
### Dead code 의 delete (with tooling)
```bash
# TypeScript — ts-prune
npx ts-prune | grep -v "(used in module)"
# Python — vulture
vulture src/ --min-confidence 80
```
### 매 long function 의 extract
```python
# Before — 매 80-line function
def process_order(order):
# validate
if not order.items: raise ...
if order.total < 0: raise ...
# apply discount
...
# charge
...
# After
def process_order(order):
_validate(order)
discounted = _apply_discount(order)
return _charge(discounted)
```
### 매 LLM-assisted batch refactor
```bash
# Cursor / Claude Code — 매 file 의 select 후
# "매 magic number 의 const 의 extract, 매 var 의 const 의 promote, 매 docstring 의 add"
```
### Pre-commit hook (ratchet)
```yaml
# .pre-commit-config.yaml
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.5.0
hooks: [{ id: ruff, args: [--fix] }]
- repo: local
hooks:
- id: complexity-check
entry: radon cc -n C src/
language: system
```
### 매 TODO/FIXME 의 ticket 의 promote
```bash
# 매 grep 의 FIXME 의 collect → 매 issue tracker 의 file
rg -n "FIXME|HACK|XXX" --json | jq -r '.data.lines.text'
```
## 매 결정 기준
| 상황 | Approach |
|---|---|
| 매 typo · rename · dead code | 매 fix on sight |
| 매 architectural smell | Ticket 의 file — 매 separate effort |
| 매 PR 매 already large | Cleanup 의 follow-up PR 의 defer |
| 매 hot path performance | Benchmark first — 매 cleanup 의 not change behavior 의 verify |
| 매 legacy code 의 untested | Test 의 add first → 매 then refactor |
**기본값**: 매 touch 했으면 매 5분 cleanup 의 add — 매 separate commit, 매 PR description 의 mention.
## 🔗 Graph
- 부모: [[Clean_Code]]
- 응용: [[Refactoring_Best_Practices|Refactoring]] · [[Code_Review]] · [[Technical_Debt]]
- Adjacent: [[YAGNI]] · [[Single_Responsibility]]
## 🤖 LLM 활용
**언제**: 매 file 의 read 한 후 매 "이 file 의 small improvement 5개 의 suggest" — 매 LLM 의 human eye 보다 빠르게 spot.
**언제 X**: 매 critical path · 매 high-stakes module — 매 unintended behavior change 의 risk.
## ❌ 안티패턴
- **Big bang refactor**: 매 PR 매 unrelated cleanup × 50 — 매 review 의 impossible.
- **Drive-by style change**: 매 team convention 의 무시 한 personal preference.
- **Cleanup commit 매 mix**: 매 main change 와 cleanup 의 same commit — 매 git blame 의 noise.
- **Test 의 break**: 매 cleanup 의 behavior 의 change — 매 test 의 guard.
- **Scope creep**: 매 5분 cleanup 매 2시간 rabbit hole — stop · ticket · commit.
## 🧪 검증 / 중복
- Verified (Robert C. Martin *Clean Code* ch1; Kent Beck *Tidy First?* 2024).
- 신뢰도 A.
## 🕓 Changelog
| 날짜 | 변경 |
|---|---|
| 2026-05-08 | Phase 1 |
| 2026-05-10 | Manual cleanup — patterns, LLM-assisted refactor, anti-patterns |