15. Inspections / Code Reviews
Learning Goals
- ๋ค์ํ Formality level์ ๊ฐ์ง Peer review์ ํํ ์ดํด
- Commit review system์ ์ฌ์ฉํ ๊ฑด์ค์ ์ธ Modern code review ์ฐธ์ฌ
- Code review์์ ์ข์ Checklists์ ์ด์ ๊ณผ ์์ฑ ์ค๋ช
- Code review์ ์ฌํ์ , ๋ฌธํ์ ๋ฌธ์ ์ํ
- ํ๋ ๊ธฐ์ ๊ธฐ์ ์ Commit review ๋๊ธฐ์ ์ด์ ๋์กฐ
Intuition
"Many eyes make all bugs shallow"
(๋ง์ ๋์ด ์์ผ๋ฉด ๋ชจ๋ ๋ฒ๊ทธ๋ ์์์ง๋ค)
Linus' law
"Have peers, rather than customers, find defects"
(๊ณ ๊ฐ์ด ์๋ ๋๋ฃ๊ฐ ๊ฒฐํจ์ ์ฐพ๊ฒ ํ๋ผ)
Karl Wiegers
Isnโt Testing Sufficient?
- ์ค๋ฅ๊ฐ ๋ค๋ฅธ ์ค๋ฅ๋ฅผ ์ํํ ์ ์์
- ์์ฑ๋ ๊ตฌํ๋ง ํ ์คํธ ๊ฐ๋ฅ (ํนํ Scalability, Performance)
- Design documents๋ ํ ์คํธ ๋ถ๊ฐ
- Tests๋ Code quality๋ฅผ ํ์ธํ์ง ์์
- ๋ง์ ํ์ง ์์ฑ(์: Security, Compliance, Scalability)์ ํ ์คํธํ๊ธฐ ์ด๋ ค์
A Second Pair of Eyes
- ๋ค๋ฅธ ๋ฐฐ๊ฒฝ๊ณผ ๊ฒฝํ ๋ณด์
- ์ ๋ต์ ๋ํ ์ ์ ๊ฒฌ ์์(No preconceived idea)
- "์๋ํ๋ ๊ฒ"์ ํธํฅ๋์ง ์์
Software Code Reviews
Code Reviews in GitHub
- Pull requests๋ฅผ ํตํด [Git] repository์ Pushํ ๋ณ๊ฒฝ ์ฌํญ ๊ณต์
- Pull request๊ฐ ์ด๋ฆฌ๋ฉด Collaborators์ ์ ์ฌ์ ๋ณ๊ฒฝ ์ฌํญ์ ๋ ผ์ํ๊ณ ๊ฒํ ํ๋ฉฐ Repository์ Merge ๋๊ธฐ ์ ํ์ Commits ์ถ๊ฐ ๊ฐ๋ฅ
- ๋ค๋ฅธ ๊ธฐ์ฌ์๋ค์ ์ ์๋ ๋ณ๊ฒฝ ์ฌํญ ๊ฒํ , Review comments ์ถ๊ฐ, PR ํ ๋ก ์ฐธ์ฌ, PR์ Commits ์ถ๊ฐ ๊ฐ๋ฅ
Code Reviews in VS Team
- Code check-in ์ Visual Studio๋ฅผ ์ฌ์ฉํด ํ์์๊ฒ ๋ฆฌ๋ทฐ ์์ฒญ ๊ฐ๋ฅ
- ์์ฒญ์ Team Explorer์ "My Work" ํ์ด์ง์ ํ์๋จ
Google's Code Review Flow
- ์ฌ์ฉ์๊ฐ ๋ณ๊ฒฝ ์ฌํญ ์์ฑ ํ Snapshot(Patch ๋ฐ ์ค๋ช )์ Code review tool์ ์ ๋ก๋
- Author๋ ์ด๊ธฐ Patch๋ฅผ ์ฌ์ฉํด Automated review comments ์ ์ฉ ๋๋ Self-review ์ํ
- Author๊ฐ Diff์ ๋ง์กฑํ๋ฉด ํ๋ ์ด์์ Reviewers์๊ฒ ๋ฉ์ผ ๋ฐ์ก (์๋ฆผ ๋ฐ ์ฝ๋ฉํธ ์์ฒญ)
- Reviewers๋ Tool์์ ๋ณ๊ฒฝ ์ฌํญ์ ์ด๊ณ Diff์ Comments ๊ฒ์ (๋ช ์์ ํด๊ฒฐ ์์ฒญ ๋๋ ๋จ์ ์ ๋ณด์ฑ)
- Author๋ ํผ๋๋ฐฑ ๊ธฐ๋ฐ์ผ๋ก ์์ ๋ฐ ์ Snapshots ์ ๋ก๋ ํ ๋ต๋ณ (4, 5๋จ๊ณ ๋ฐ๋ณต ๊ฐ๋ฅ)
- Reviewers๊ฐ ์ต์ ์ํ์ ๋ง์กฑํ๋ฉด "LGTM"(Looks Good To Me)์ผ๋ก ์๋ฝ (๋ณดํต 1๊ฐ์ LGTM ํ์ํ๋ ๊ด๋ก์ ์ ์ ๋์ ์๊ตฌ ๊ฐ๋ฅ)
- LGTM ํ Author๋ ๋ชจ๋ Comments๋ฅผ ํด๊ฒฐํ๊ณ ์น์ธ๋ฐ์ ๊ฒฝ์ฐ Codebase์ ๋ณ๊ฒฝ ์ฌํญ Commit
Code Review Goals
- Finding defects
- Low-level ๋ฐ High-level issue ๋ชจ๋ ํฌํจ (Requirements/Design/Code)
- Code improvement
- Readability, Formatting, Commenting, Consistency, Dead code ์ ๊ฑฐ, Naming, Coding standards
- ๋์ ์๋ฃจ์ ์๋ณ
- Knowledge transfer
- API ์ฌ์ฉ๋ฒ, ๋ผ์ด๋ธ๋ฌ๋ฆฌ, Best practices, Team conventions, System design, "Tricks", ํนํ Junior developers ๊ต์ก
- Team awareness ๋ฐ Transparency
- ๋ค๋ฅธ ์ฌ๋์ด ๋ณ๊ฒฝ ์ฌํญ "Double check", ํน์ ๊ฐ๋ฐ์ ๋๋ ์ ์ฒด ํ์ ๊ณต์ง("FYI")
- Shared code ownership
- ๋นํ๊ณผ ๋ณ๊ฒฝ์ ๋ํ ๊ฐ๋ฐฉ์ฑ, ๊ฐ๋ฐ์๊ฐ ์์ ์ ์ฝ๋์ ๋ํด ๋ ๋ฐฉ์ด์ ์ด๊ฒ ๋จ
Developersโ Expectations

Actual Outcomes

- ๊ฐ์ฅ ๋น๋ฒํจ: Code improvements (29%)
- 58 Better coding practices
- 55 Removing unused/dead code
- 52 Improving readability
- ๋ณดํต: Defect finding (14%)
- 65 Logical issues (๋ณต์กํ์ง ์์ ๋ ผ๋ฆฌ ์ค๋ฅ, ์: Corner cases, ์ค์ ๊ฐ, ์ฐ์ฐ์ ์ฐ์ ์์)
- 6 High-level issues
- 5 Security issues
- 3 Wrong exception handling
- ๋๋ฌพ: Knowledge transfer
- 12 ๋ด๋ถ/์ธ๋ถ ๋ฌธ์ ํฌ์ธํฐ ๋ฑ
Expectation vs Outcomes
- ๊ธฐ๋์ ๊ฒฐ๊ณผ ์ฌ์ด์ ๋ถ์ผ์น ์กด์ฌ
Expectation/Outcome Mismatch
- Code reviews์ ๋ฎ์ ํ์ง
- Reviewers๊ฐ ์ฌ์ด ์ค๋ฅ(Formatting ๋ฑ)๋ง ์ฐพ์
- ์ฌ๊ฐํ ์ค๋ฅ ๋์นจ
- Understanding(์ดํด)์ด ์ฃผ๋ ๊ณผ์
- ๋ณ๊ฒฝ ์ด์ ์ดํด
- Code ๋ฐ Context ์ดํด
- ์ง๋ฌธ์ ์ํ Feedback channels ํ์
- ๊ฒฐ๊ณผ๋ฌผ์ ๋ํ Quality assurance ๋ถ์ฌ
Formal Inspection
- 70๋ ๋ IBM์์ ์์ด๋์ด ๋์คํ
- 80๋ ๋ ๋๋ฆฌ ์ฑํ, ๋ง์ ์ฐ๊ตฌ ์งํ (๋๋ก๋ Component testing ๋์ฒด)
- ๊ฐ๋ฐ์ ๊ทธ๋ฃน์ด Code๋ ๋ค๋ฅธ Artifacts๋ฅผ ๊ณต์์ ์ผ๋ก ๊ฒํ ํ๊ธฐ ์ํด ๋ง๋จ
- ๋ฒ๊ทธ๋ฅผ ์ฐพ๋ ๊ฐ์ฅ ํจ๊ณผ์ ์ธ ์ ๊ทผ๋ฒ
- ์ผ๋ฐ์ ์ผ๋ก Inspections๋ก 60-90%์ ๋ฒ๊ทธ ๋ฐ๊ฒฌ
- ๋น์ฉ์ด ๋ง์ด ๋ค๊ณ ๋ ธ๋ ์ง์ฝ์
Inspection Team and Roles
- ๋ณดํต 4-5๋ช (์ต์ 3๋ช )
- Author: ์์ฑ์
- Inspector(s): ๊ฒฐํจ(Faults) ๋ฐ ๊ด๋ฒ์ํ issue ๋ฐ๊ฒฌ
- Reader: ํ์์์ Code๋ Document ์ ์
- Scribe: ๊ฒฐ๊ณผ ๊ธฐ๋ก
- Moderator: ํ๋ก์ธ์ค ๊ด๋ฆฌ, ์งํ(Facilitates), ๋ณด๊ณ
Inspection Process

- Planning
- Overview
- Preparation
- Meeting
- Rework
- Follow-up
- ์ฐธ์ฌ์
- Author
- Moderator
- Inspectors (Scribe, Reader, Verifier ํฌํจ)
Inspection Steps
- Planning (Moderator ์ ์ )
- Overview (๊ฐ๋ต): Author๊ฐ ํ์์์ Context ์ ์
- Preparation (1-2์๊ฐ): ๋ชจ๋ Reviewer๊ฐ ๊ฐ๋ณ์ ์ผ๋ก Code ๊ฒ์ฌ
- Meeting (1์๊ฐ)
- Reader๊ฐ Code ์ ์
- ๋ชจ๋ Reviewers๊ฐ issue ์๋ณ
- ํ์์์๋ issue ๋ฐ๊ฒฌ๋ง ํ๊ณ , ์๋ฃจ์ ํ ์๋ ์ค์ issue ์ฌ๋ถ๋ ๋ ผ์ํ์ง ์์
- Rework
- Follow-up (Verifier๊ฐ ๋ณ๊ฒฝ ์ฌํญ ํ์ธ)
Checklists
- ๋ฌด์์ ์ฐพ์์ผ ํ ์ง ์๊ธฐ์ํด
- ๊ณผ๊ฑฐ์ ๋ฐ๊ฒฌ๋ issue ํฌํจ
- ์์์ ์ค์ํ ํญ๋ชฉ์ ์ง์คํ๋ ๊ฒ์ด ์ข์
- ์์:
- ์ฌ์ฉ ์ ๋ชจ๋ ๋ณ์ ์ด๊ธฐํ ์ฌ๋ถ
- ๋ชจ๋ ๋ณ์ ์ฌ์ฉ ์ฌ๋ถ
- If/While ๋ฌธ์ ์กฐ๊ฑด ์ ํ์ฑ
- ๊ฐ Loop์ ์ข ๋ฃ ์ฌ๋ถ
- Function parameters์ ์ฌ๋ฐ๋ฅธ ํ์ ๋ฐ ์์
- Linked lists์ ํจ์จ์ ์ํ
- ๋์ ํ ๋น๋ ๋ฉ๋ชจ๋ฆฌ ํด์
- ์๊ธฐ์น ์์ ์ ๋ ฅ์ผ๋ก ์ธํ Corruption ๊ฐ๋ฅ์ฑ
- ๋ชจ๋ ๊ฐ๋ฅํ Error conditions ์ฒ๋ฆฌ ์ฌ๋ถ
- Strings์ ์ฌ๋ฐ๋ฅธ Sanitization ์ฌ๋ถ
Perspective-based Inspections
- ์๋ก ๋ค๋ฅธ ์ ๋ฌธ ๋ถ์ผ๋ Focus/Checklists๋ฅผ ๊ฐ์ง Inspectors ๋ฐฐ์น
- ๋์์ ์ฌ๊ณ ํจํด ์ฅ๋ ค
- Reviewers๊ฐ ๋ฌธ์์ ๋ค๋ฅธ ์์น์์ ์์ํ๋๋ก ํจ
- ๊ฐ์ ์์น์์ ์ง์ค๋ ฅ์ ์๋ ๊ฒ ๋ฐฉ์ง
- ํนํ Preparation ๋จ๊ณ์์ ์ ํจ
- ์ถํ๋ ๋ฐ์ดํฐ๋ ์ ์ง๋ง ํจ๊ณผ์ ์ธ ๊ดํ์ผ๋ก ๊ฐ์ฃผ๋จ
Process Details
- Authors๋ Code๋ฅผ ์ค๋ช
ํ๊ฑฐ๋ ๋ฐฉ์ดํ์ง ์์ (๊ฐ๊ด์ ์ด์ง ์์)
- Author Moderator Scribe, Reader
- Author๋ ์ง๋ฌธ๊ณผ ์คํด๋ฅผ ๊ด์ฐฐํ๊ณ ํ์์ issue๋ฅผ ๋ช ํํ ํ๊ธฐ ์ํด ํ์ ์ฐธ์
- Reader(optional)๋ Code๋ฅผ ํ ์ค์ฉ ์ฝ์ผ๋ฉฐ ์ค๋ช
- Code๋ฅผ ์๋ฆฌ ๋ด์ด ์ฝ์ผ๋ฉด ๋ ๊น์ ์ดํด ํ์
- ํด์์ ์ธ์ดํ(Verbalizes)ํ์ฌ ํด์์ ์ฐจ์ด ๊ด์ฐฐ ๊ฐ๋ฅ
Social Issues: Egos in Inspections
- Artifacts์ ๋ํ Author์ ์์กด๊ฐ(Self-worth)
- ๊ฒฐํจ์ ์๋ณํ๋ ๋์ ์ ์๋ ์ง์, Authors๋ฅผ ๋นํํ์ง ์์
- "๋๋ ๋ณ์
a๋ฅผ ์ด๊ธฐํํ์ง ์์์ด" "๋๋ ๋ณ์a๊ฐ ์ด๋์ ์ด๊ธฐํ๋๋์ง ๋ชป ์ฐพ๊ฒ ์ด"
- "๋๋ ๋ณ์
- Code ๋ฐฉ์ด ํํผ, ์๋ฃจ์ /๋์ ํ ๋ก ํํผ
- Reviewers๋ ์์ ์ด ๋ ๋ซ๊ฑฐ๋ ๋๋ํจ์ ๊ณผ์ํ์ง ๋ง ๊ฒ
- Guidelines๊ฐ ์๋ค๋ฉด Style ํ ๋ก ํํผ
- ๊ฒฐํจ ํด๊ฒฐ ๋ฐฉ์์ Author๊ฐ ๊ฒฐ์
Social Issues: Inspection Incentive
- Moderator๋ ํ ๋ก ์ ์งํํ๊ณ ์ถฉ๋ ํด๊ฒฐํด์ผ ํจ
- ํ์์ ๊ฒฝ์์ง(Management) ํฌํจ ๊ธ์ง
- HR ํ๊ฐ์ ์ฌ์ฉ ๊ธ์ง
- "Inspection ์ค 5๊ฐ ์ด์ ๋ฒ๊ทธ ๋ฐ๊ฒฌ ์ Author์๊ฒ ๋ถ์ด์ต" ๊ฐ์ ๊ฒฝ์ฐ
- ํํผ, ๋ถํ ์ ์ถ, ๊ฒฐํจ ์ง์ ํํผ, Pre-reviews ๊ฐ์ต ๋ฑ์ผ๋ก ์ด์ด์ง
- Quality์ ๋ํ ์ฑ
์์ Reviewers๊ฐ ์๋ Authors์๊ฒ ์์
- "์ ๊ณ ์ณ, Reviewers๊ฐ ์ฐพ์ ํ ๋ฐ"๋ผ๋ ํ๋ ๋ฐฉ์ง
Root Cause Analysis
- ๋น๋ฉดํ ํผ์ฆ ๋๋จธ๋ฅผ ๋ด
- ์ด ๋ฌธ์ ๋ฅผ ํผํ๊ธฐ ์ํด ๊ฐ๋ฐ ํ๋ก์ธ์ค๋ฅผ ๊ฐ์ ํ๋ ๋ฐฉ๋ฒ
- ๊ฐ๋ฐ ํ๋ก์ธ์ค ์ฌ๊ตฌ์กฐํ
- ์๋ก์ด Policies
- ์๋ก์ด ๊ฐ๋ฐ ๋๊ตฌ
- ์๋ก์ด ์ธ์ด
- ์๋ก์ด ๋ถ์ ๋๊ตฌ
When to Inspect
- Milestones ์ด์
- ๊ฐ๋ฐ ์ค ์ ์ง์ (Incremental) Inspections
- ๋์ค๋ณด๋ค ์ด๊ธฐ๊ฐ ์ข์
- ๋ ์์ ์กฐ๊ฐ, ํฅํ ๊ฐ๋ฐ์ ์ํฅ ์ค ๊ธฐํ
- ๋๊ท๋ชจ Code bases๋ ๋ฆฌ๋ทฐ ๋น์ฉ์ด ๋๊ณ ์ข์ ๊ฐ ์ ๋ฐ ๊ฐ๋ฅ
- ๋์ค๋ณด๋ค ์ด๊ธฐ๊ฐ ์ข์
- ๋ถํ ์ ๋ณต(Break down, divide and conquer)
- ์ค์ Components ์ง์ค
- ์ฒซ ์ธ์ ์ Defect density๋ฅผ ์๋ณํ์ฌ ์ถ๊ฐ Inspections ํ์์ฑ ๊ฐ์ด๋
Reviews as Part of a Milestone

- Task X, Task Y ์ํ ํ Review ์งํ
- Milestone ๋๋ฌ ์ ์ ์ ํ ์์ ์ธ์ง ํ์ธ
- Rework ๊ณผ์ ์ ๊ฑฐ์ณ Milestone ๋ฌ์ฑ
Guidelines for Inspections
- ๋ค์ ๊ธฐ์ ์ ํ๋ก์ ํธ ๋ฐ ์คํ์์ ์์ง๋จ
- ์ฝ๊ฒ ์ธก์ ๊ฐ๋ฅํ ๋ช ๊ฐ์ง Metrics
- Effort, Issues found, Lines of code inspected ๋ฑ
Focus Fatigue

- ๊ถ์ฅ ์ฌํญ: ์ธ์ ๋น 60๋ถ ์ด๊ณผ ๊ธ์ง
Inspection Speed

- 400 LOC/h ์ด์ ์ ๋ฆฌ๋ทฐ๊ฐ ์์์ง(Shallow)
- ๊ถ์ฅ ์ฌํญ: 1์๊ฐ ๋ฆฌ๋ทฐ ์ธ์ ์ 400 LOC ๋ฏธ๋ง ์ผ์ ์ก๊ธฐ
Importance of Context
- Context dependencies๊ฐ ์ ์ Code๊ฐ ๋ฆฌ๋ทฐํ๊ธฐ ์ฌ์
- Reviewers๋ ๊ด๋ จ ํ์ผ ํ์ธ ํ์
- Modularity (Small interfaces, High cohesion, Low coupling ๋ฑ) ํ์
Are Meetings Required

- ๋๋ถ๋ถ์ issue๋ Meeting์ด ์๋ Preparation ๋จ๊ณ์์ ๋ฐ๊ฒฌ๋จ
- ์ ์๋ ์๋์ง ํจ๊ณผ๋ ๋ฎ์ ์ํฅ๋ง ๋ฏธ์นจ
- ์ฃผ์ฅ: Meetings์์ ๋ฐ๊ฒฌ๋๋ ๊ฒฐํจ์ ์ข ์ข ๋ ๋ฏธ๋ฌํจ(Subtle)
False Positives
- ๋ฐ๊ฒฌ๋ issue์ ์ฝ 25%๋ False positives
- Meeting ์ค ํ ๋ก ํํผ
- Meeting ์ค ํผ๋์ ๋ฌธ์๊ฐ ๋ ๋ช ํํด์ผ ํ๋ค๋ ์งํ(Indicator)
Self-checks Can Find Half the Issues

- Authors๊ฐ Inspection ์ ๋ฌธ์๋ฅผ Self-checkํจ
The Goal Is Not To Be โRightโ (itโs to save $)
"ํผ๋ก์ค์ ์น๋ฆฌ(Pyrrhic victory)๋ ์น๋ฆฌ์์๊ฒ ๋ง๋ํ ๋๊ฐ๋ฅผ ์น๋ฅด๊ฒ ํ์ฌ ํจ๋ฐฐ์ ๋ค๋ฆ์๋ ์น๋ฆฌ์ด๋ค.
์ฅ๊ธฐ์ ๋ฐ์ ์ ์ ํดํ๊ฑฐ๋ ์ง์ ํ ์ฑ์ทจ๊ฐ์ ๋ฌดํจํํ๋ค."
- ์ณ๋ค๋ ๊ฒ(Being right)์ด ํญ์ ์ค์ํ ๊ฒ์ ์๋
- "๋ด ์ฝ๋๊ฐ ์๋ํ์ง ์๋๋ค"๋ ๋ง์ ๋ค์์ ๋ ๊ณ ๋ คํ ์ฌ๊ณ ๋ฐฉ์
- "์ด ์ฌ๋์๊ฒ ์ ํ๋ ธ๋์ง ๋งํด์ค์ผ์ง" (X)
- "๋ด ์ฝ๋๊ฐ ์ ์๋ํ๋์ง ๋ช ํํ ํด์ผ๊ฒ ๋ค" (O)
Inspections vs Reviews: Costs
- Formal inspections ๋ฐ Modern code reviews
- Formal inspections๋ ๋งค์ฐ ๋น์ (์ธ์ ๋น ์ฝ 1 Developer-day)
- Passaround review๋ ๋ถ์ฐํ, ๋น๋๊ธฐ์ (Asynchronous)
- Code reviews ๋ Testing
- Code reviews๊ฐ ๋น์ฉ ํจ์จ์ ์ด๋ผ ์ฃผ์ฅ๋จ
- Code reviews ๋ ๋ฒ๊ทธ๋ฅผ ์ฐพ์ง ๋ชปํ๋ ๋น์ฉ ๋น๊ต
Code Review by Formality
- Inspection (๊ฐ์ฅ formalํจ)
- Walkthrough
- Pair Programming
- Passaround ("Modern code reviews")
- Ad hoc review
Differences Among Peer Review Types
| Review Type | Planning | Preparation | Meeting | Correction | Verification |
|---|---|---|---|---|---|
| Inspection | O | O | O | O | O |
| Walkthrough | O | O | O | O | X |
| Pair Programming | O | X | Continuous | O | O |
| Passaround | X | O | Rarely | O | X |
| Ad Hoc | X | X | O | O | X |
Experience (Studies/Claims)
- Raytheon
- "Rework" ๋น์ฉ 41%์์ 20%๋ก ๊ฐ์
- Integration effort 80% ๊ฐ์
- Paulk et al. : Space shuttle software ์์ ๋น์ฉ
- Inspection ์ค ๋ฐ๊ฒฌ ์ $1
- System test ์ค ๋ฐ๊ฒฌ ์ $13
- Delivery ํ ๋ฐ๊ฒฌ ์ $92
- IBM
- Inspection 1์๊ฐ์ด Testing 20์๊ฐ ์ ์ฝ
- R. Grady, HP์ ํจ์จ์ฑ ๋ฐ์ดํฐ (Defects/h)
- System use:
0.21 - Black box testing:
0.28 - White box testing:
0.32 - Reading/inspection:
1.06
- System use:

