--- 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 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 ## 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 |