Files
2nd/10_Wiki/Topics/Other/Program Comprehension Strategies.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

168 lines
5.9 KiB
Markdown

---
id: wiki-2026-0508-program-comprehension-strategies
title: Program Comprehension Strategies
category: 10_Wiki/Topics
status: verified
canonical_id: self
aliases: [Code Reading, Code Comprehension, Mental Models of Code]
duplicate_of: none
source_trust_level: A
confidence_score: 0.9
verification_status: applied
tags: [software-engineering, cognition, code-review, onboarding]
raw_sources: []
last_reinforced: 2026-05-10
github_commit: pending
tech_stack:
language: multi
framework: cognitive-software-engineering
---
# Program Comprehension Strategies
## 매 한 줄
> **"매 90% of programming is reading code, not writing it."**. 매 Brooks (1983), Pennington (1987), Soloway (1986) 의 cognitive software engineering 연구에서 출발한 매 분야 — 매 code → mental model 변환의 strategies. 매 2026 LLM 시대에는 매 Cursor/Claude Code 의 contextual indexing 이 매 human comprehension 을 augment.
## 매 핵심
### 매 3대 strategy
- **Top-down (Brooks)**: 매 hypothesis 형성 → code 로 verify. 매 domain expert 가 사용.
- **Bottom-up (Pennington)**: 매 statement → control-flow → data-flow → program model. 매 novice 가 사용.
- **Opportunistic (mixed)**: 매 expert programmer 의 실제 행동 — top-down 시작, beacon 발견 시 bottom-up 으로 dive.
### 매 cognitive constructs
- **Beacons**: 매 recognizable patterns (e.g., `for(i=0; i<n; i++)` → 매 loop, `swap(a,b)` → 매 sort).
- **Plans**: 매 stereotypical solutions (e.g., search plan, accumulator plan).
- **Chunks**: 매 functionally cohesive code groups stored as 1 unit in working memory.
### 매 응용
1. Code review: 매 reviewer 는 top-down — PR 의 의도 파악 후 specific changes 검증.
2. Onboarding: 매 new dev 는 bottom-up — small fixes 로 시작, 점진적 chunking.
3. AI-assisted reading: 매 LLM 에게 code summarization → human 이 hypothesis 생성.
## 💻 패턴
### Pattern 1: Top-down hypothesis-driven reading
```python
# 매 step 1: read README / docstring → 매 form hypothesis
# 매 step 2: locate entry point (main, app.py)
# 매 step 3: trace only the path that confirms/refutes hypothesis
def trace_hypothesis(repo, hypothesis):
entry = find_entry_point(repo)
call_graph = build_call_graph(entry)
relevant = filter_by_keyword(call_graph, hypothesis.keywords)
return relevant
```
### Pattern 2: Beacon recognition (LLM-augmented)
```python
import anthropic
client = anthropic.Anthropic()
def extract_beacons(code: str) -> list[str]:
resp = client.messages.create(
model="claude-opus-4-7",
max_tokens=1024,
system="Identify recognizable code patterns (beacons) and name their plan.",
messages=[{"role": "user", "content": f"```\n{code}\n```"}],
)
return parse_beacons(resp.content[0].text)
```
### Pattern 3: Chunking via cohesion analysis
```python
def chunk_function(ast_node):
"""매 group statements by 매 shared variables (cohesion)."""
chunks, current = [], []
last_vars = set()
for stmt in ast_node.body:
vars = extract_vars(stmt)
if last_vars and not (vars & last_vars):
chunks.append(current)
current = []
current.append(stmt)
last_vars = vars
if current:
chunks.append(current)
return chunks
```
### Pattern 4: Cross-reference walking (bottom-up)
```bash
# 매 ripgrep + ctags-driven exploration
rg -l "AuthService" --type ts | head -5
rg "class AuthService" --type ts -A 30
rg "new AuthService\(" --type ts # 매 callers
```
### Pattern 5: LLM-driven code summarization
```python
# 매 Claude Code-style structured summary
PROMPT = """Summarize this file with:
1. 매 PURPOSE (1 sentence)
2. 매 KEY DATA STRUCTURES
3. 매 PUBLIC API
4. 매 NON-OBVIOUS CONTRACTS / INVARIANTS
5. 매 DEPENDENCIES (incoming + outgoing)
"""
def summarize(file_path):
code = open(file_path).read()
return claude_call(PROMPT + f"\n```\n{code}\n```")
```
### Pattern 6: Mental model checkpointing
```markdown
<!-- 매 personal-notes.md per repo while reading -->
## Module: auth/
- Purpose: JWT issuance & verification
- Entry: `auth/router.ts:loginHandler`
- Key invariant: tokens always include `iss=our-domain`
- Open Q: where is refresh-token rotation?
```
### Pattern 7: Diagram-first — produce dependency graph before reading
```bash
madge --image deps.svg src/
# 매 visual chunking — see clusters before diving
```
## 매 결정 기준
| 상황 | Strategy |
|---|---|
| 매 domain familiar, code new | Top-down |
| 매 domain new, code small | Bottom-up |
| 매 large unknown codebase | Opportunistic + diagram first |
| 매 bug hunt | Bottom-up from stack trace |
| 매 architecture review | Top-down from entry points |
| 매 LLM augmentation | Summarize → form hypothesis → verify |
**기본값**: 매 opportunistic — 매 README + entry point 부터 시작, beacon 발견 시 dive.
## 🔗 Graph
- 부모: [[Cognitive Psychology]]
- 변형: [[Code Review]] · [[Onboarding]]
- 응용: [[Refactoring_Best_Practices|Refactoring]]
- Adjacent: [[Mental_Models|Mental Models]] · [[Working Memory]] · [[AST]]
## 🤖 LLM 활용
**언제**: 매 onboarding new repo, 매 reviewing large PR, 매 understanding legacy code, 매 building mental model.
**언제 X**: 매 1-line hot-fix 에 over-engineering 하지 마라.
## ❌ 안티패턴
- **Read everything linearly**: 매 working memory 초과 — chunking 없이 무너짐.
- **Skip the README**: 매 hypothesis 없이 bottom-up 만 → 매 lost in details.
- **No checkpointing**: 매 1시간 후 모두 잊음 — write down mental model.
- **Trust LLM summary blindly**: 매 hallucination 위험 — 매 verify on key claims.
## 🧪 검증 / 중복
- Verified (Brooks 1983, Pennington 1987, Soloway & Ehrlich 1984, Storey 2006 review).
- 신뢰도 A.
## 🕓 Changelog
| 날짜 | 변경 |
|---|---|
| 2026-05-08 | Phase 1 |
| 2026-05-10 | Manual cleanup — top-down/bottom-up/opportunistic + LLM augmentation |