Code review that teaches
Why it matters
- A review that only says 'looks good' or 'fix this' teaches the author nothing. In a Kotlin codebase with Jetpack Compose state hoisting or
rememberkeys, the why behind a comment is what the author carries into the next PR. - Interviewers at senior and staff level ask you to describe your code review process. They want to hear about blocking vs. nit labels, small PRs, and how
ktlintordetektremove style noise so humans focus on logic. - Small PRs are easier to review correctly. A large diff hides a wrong
ViewModelstate transition or a missingrememberkey that a small diff would make obvious. - Reviewing the code, not the person, keeps psychological safety high. Google's public code review guide says the same: comment on the code, never on the developer.
The simple explanation
- A code review is like a peer edit of a manuscript, not a grade.
- You mark the paragraph that confuses the reader, not the author who wrote it.
- A red pen for blocking issues, a blue pen for nits, a green pen for praise.
- You hand the manuscript back with notes, not a new manuscript.
- The author decides which blue-pen marks to act on before the next pass.
What is a code review that teaches? It is a review where every comment says what is wrong, why it matters, and whether it blocks the merge, so the author learns a rule they can reuse instead of just applying one fix. The core mechanism is separating signal from noise and teaching through the diff.
Blocking vs. nit. A blocking issue stops the merge: a ViewModel that holds an Activity Context (a leak), a runCatching around a suspend call that swallows CancellationException, a missing @HiltViewModel that crashes at runtime. A nit is style or naming: a variable called data that could be userList. Label them differently. Google's code review guide suggests prefixes such as Nit:, Optional: and FYI:; many teams add blocking: and question: so the author knows what must change before merge.
Explain why. Instead of "use viewModelScope here", write "viewModelScope is cancelled when the ViewModel is cleared; a GlobalScope coroutine keeps running after the screen is gone." The author learns the rule, not just the fix.
Automate style. Run ktlint and detekt in CI. detekt ships rules such as MagicNumber, LongMethod and TooManyFunctions. This removes most nit comments and lets reviewers focus on logic, state flow and Compose correctness.
Small PRs. Aim for small, focused PRs. Google's guide says about 100 lines is usually a reasonable change and 1000 lines is usually too large, while leaving it to reviewer judgment. A PR that touches MainActivity, three ViewModels and a new Compose screen is probably three PRs.
| Category | Example in Android/Kotlin | Action |
|---|---|---|
| Blocking | ViewModel keeps an Activity reference | Must fix before merge |
| Nit | Variable list → items | Suggest, author decides |
| Question | remember with no key for a value derived from userId | Ask, do not assume |
| Praise | collectAsStateWithLifecycle() used for the screen state | Say so explicitly |
Notes
- Review the change, not the person. Phrase comments about the code:
"This path skips the null check"not"You forgot the null check." - Separate blocking issues (must fix before merge) from nits (suggestions the author may skip). Use prefixes like
blocking:andnit:in review comments. - Always explain why.
"Use viewModelScope because it cancels with the ViewModel lifecycle"teaches;"use viewModelScope"does not. - Automate style with
ktlintanddetektin CI. This removes formatting and naming nits so human reviewers focus on logic and state flow. - Keep PRs small and focused. A PR that mixes a new Compose screen, a
ViewModel, and aRepositorychange should be split. - In Jetpack Compose, watch for
rememberscope errors, missingkeyparameters inLazyColumn, andLaunchedEffectthat should beDisposableEffectfor cleanup. - Praise specific good choices. A one-line
"Nice use of StateFlow here"costs nothing and reinforces the pattern for the whole team. - A review is a conversation, not a verdict. The author can push back on a nit. Blocking issues need a reason, not just a rule citation.
- In interviews, describe your process concretely: PR size limit, CI lint gate, blocking/nit tags, and how you handle a disagreement with the author.
- This skill transfers directly to writing design docs, mentoring juniors, and making technical decisions with the team.
Code example
A JSON PR checklist a team can paste into a GitHub or GitLab PR template. It forces the author to answer the questions a reviewer would ask, reducing back-and-forth on Android and Kotlin changes.
{
"title": "PR Checklist – Android / Kotlin",
"sections": [
{
"name": "Before you open the PR",
"items": [
"Diff is small and focused (split if large)",
"ktlint and detekt pass locally (./gradlew ktlintCheck detekt)",
"No TODO or FIXME left without a linked issue",
"Any @OptIn to an experimental API is deliberate and mentioned in the description"
]
},
{
"name": "Correctness",
"items": [
"ViewModel exposes read-only StateFlow; the MutableStateFlow stays private",
"Coroutines use viewModelScope or lifecycleScope, not GlobalScope",
"CancellationException is never swallowed (no bare runCatching around suspend calls)",
"remember keys include every value the remembered result depends on",
"Screens collect state with collectAsStateWithLifecycle()",
"Null-safety: no !! on nullable values from the network layer"
]
},
{
"name": "Review tags",
"items": [
"blocking: must fix before merge (bug, crash, leak)",
"nit: suggestion, author may skip",
"question: reviewer is unsure, needs discussion",
"praise: call out a good pattern explicitly"
]
}
]
}- The checklist is a template, not a rulebook. Teams adapt items to their stack (Hilt vs. manual DI, Compose vs. XML).
ktlintCheckcomes from theorg.jlleitschuh.gradle.ktlintplugin anddetektfrom theio.gitlab.arturbosch.detektplugin; use whatever task names your build actually defines.- The "Before you open the PR" section shifts work to the author, so the reviewer spends time on logic, not formatting.
- The review-tags section makes blocking vs. nit explicit in every comment, so the author never has to guess what stops the merge.
Run the idea in plain Kotlin
A tiny review evaluator for a ViewModel PR: it applies the team's size limit, flags blocking comments that give no reason, and decides whether the PR can merge.
enum class Tag { BLOCKING, NIT, QUESTION, PRAISE }
data class ReviewComment(val file: String, val tag: Tag, val text: String, val why: String? = null)
data class Verdict(val canMerge: Boolean, val notes: List<String>)
const val TEAM_MAX_CHANGED_LINES = 400 // the team's own limit, not a universal rule
fun evaluate(changedLines: Int, comments: List<ReviewComment>): Verdict {
val notes = mutableListOf<String>()
if (changedLines > TEAM_MAX_CHANGED_LINES) {
notes.add("Diff has " + changedLines + " changed lines: ask the author to split it")
}
for (c in comments.filter { it.tag == Tag.BLOCKING && it.why.isNullOrBlank() }) {
notes.add("Blocking comment in " + c.file + " gives no reason: '" + c.text + "'")
}
val counts = Tag.entries.joinToString(", ") { tag ->
tag.name.lowercase() + "=" + comments.count { it.tag == tag }
}
notes.add("Comments: " + counts)
val openBlocking = comments.count { it.tag == Tag.BLOCKING }
return Verdict(canMerge = openBlocking == 0 && changedLines <= TEAM_MAX_CHANGED_LINES, notes = notes)
}
fun main() {
val comments = listOf(
ReviewComment("ProfileViewModel.kt", Tag.BLOCKING, "Do not keep the Activity in the ViewModel",
why = "the ViewModel outlives the Activity on rotation, so this leaks it"),
ReviewComment("ProfileViewModel.kt", Tag.BLOCKING, "Use viewModelScope here"),
ReviewComment("ProfileScreen.kt", Tag.NIT, "Rename data to profile"),
ReviewComment("ProfileScreen.kt", Tag.QUESTION, "Should remember be keyed on userId?"),
ReviewComment("ProfileScreen.kt", Tag.PRAISE, "Nice use of collectAsStateWithLifecycle")
)
val first = evaluate(changedLines = 180, comments = comments)
println("First pass: canMerge=" + first.canMerge)
first.notes.forEach { println(" - " + it) }
// The author fixes both blocking issues and replies to the question
val second = evaluate(changedLines = 190, comments = comments.filter { it.tag != Tag.BLOCKING })
println("Second pass: canMerge=" + second.canMerge)
second.notes.forEach { println(" - " + it) }
}Expected output:
First pass: canMerge=false
- Blocking comment in ProfileViewModel.kt gives no reason: 'Use viewModelScope here'
- Comments: blocking=2, nit=1, question=1, praise=1
Second pass: canMerge=true
- Comments: blocking=0, nit=1, question=1, praise=1
In production
- A single PR added a new settings screen, refactored the
UserViewModel, and changed theRepositoryinterface. - After merge, switching accounts showed the previous user's settings: a value computed with
remember { buildSettings(userId) }had no key, so it was never recomputed whenuserIdchanged. - The two-line mistake was easy to miss because it was buried among hundreds of changed lines across three layers.
- The fix was
remember(userId) { buildSettings(userId) }, plus a Compose UI test that switches users and asserts the new values. - The team agreed a size guideline for PRs and split the next similar change into three PRs (repository,
ViewModel, screen); a CI job posts a warning comment when a diff passes the guideline. - "Every value a
rememberblock reads is a key or is deliberately excluded" went on the review checklist, and reviewers tag such findingsblocking:.
- Every PR generated many comments, most about import order, spacing, and variable naming.
- Senior engineers stopped reviewing; PRs sat unreviewed for extended periods.
- The team had no
ktlintordetektgate in CI.
- They applied the
ktlintanddetektGradle plugins (both hook into thechecktask) and made./gradlew checka required CI step, with.editorconfigholding the formatting rules. - Reviewers agreed to label every comment
blocking:,nit:,question:orpraise:, and to skip anything the tools already enforce. - Style comments mostly disappeared from reviews, and seniors had time to review logic again.
Common mistakes
- Reviewing the person. Writing 'you always forget null checks' attacks the author and shuts down conversation. Describe the code: 'this path skips the null check on the API response.' The author fixes the code, not their self-image.
- No blocking/nit separation. If every comment looks the same, the author cannot tell which ones block merge. Tag with
blocking:ornit:so the author knows what must change and what is optional. - Saying 'use X' without 'because Y'. A bare instruction teaches nothing. 'Use
viewModelScopebecause it cancels with the ViewModel lifecycle' gives the author a rule they can apply to the next coroutine they write. - Reviewing a large, mixed PR. Large diffs hide regressions. A missing
keyin aLazyColumnor a wrongrememberscope is easy to miss in a large diff. Split the PR or ask the author to. - No automated style gate. Without
ktlintanddetektin CI, every human review spends time on import order and spacing. Automate style so reviewers focus on logic, state flow, and Compose correctness. - Never praising good code. A one-line 'nice use of
StateFlowhere' costs nothing and reinforces the pattern for the whole team. Silence reads as 'this is fine' or 'I did not look'.
Interview questions
Answer out loud first. Then reveal the answer and compare it at each depth.
“How do you structure a code review for an Android/Kotlin PR?”
“What do you do when a reviewer and an author disagree on a design choice?”
“How do you make code reviews faster without lowering quality?”
“Give an example of a review comment that teaches versus one that does not.”
Quiz
A reviewer writes 'use viewModelScope here' with no explanation. What is the main problem?
Which practice most reduces the number of nit comments in a Kotlin/Android codebase?
A PR is large and mixes a new Compose screen, a ViewModel refactor, and a Repository change. What should the reviewer do?
A ViewModel PR wraps a suspend repository call in runCatching, so cancellation is turned into a failure result. How should the reviewer label it?
0 of 4 answered
Mini task
15-minute exercise: tag a real PR
- Open a recent merged PR in your team's Android/Kotlin repo (GitHub, GitLab, or Bitbucket). Pick one that has at least 10 review comments.
- Read every comment. For each one, write a tag in the margin or a local file:
blocking– must fix before mergenit– suggestion, author may skipquestion– reviewer was unsurepraise– positive callout
- Count how many comments fall into each tag. Note the proportion that are nits.
- Pick the three most common nit comments. For each, name an existing
ktlintordetektrule (or.editorconfigsetting) that would catch it automatically. If no rule exists, write a one-sentence team convention. - Pick one blocking comment that lacked a "why." Rewrite it in two sentences: what is wrong, and why it matters (lifecycle, crash, leak, recomposition).
- Done when: you have a tagged list, a nit proportion, three automation ideas, and one rewritten blocking comment. Share the result in your team channel or a design-doc draft.