Code review that teaches

Learn to run Android and Kotlin code reviews that teach: label blocking issues and nits, explain why, automate style with ktlint and detekt, keep PRs small. About 25 minutes.

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 remember keys, 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 ktlint or detekt remove style noise so humans focus on logic.
  • Small PRs are easier to review correctly. A large diff hides a wrong ViewModel state transition or a missing remember key 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.

CategoryExample in Android/KotlinAction
BlockingViewModel keeps an Activity referenceMust fix before merge
NitVariable list → itemsSuggest, author decides
Questionremember with no key for a value derived from userIdAsk, do not assume
PraisecollectAsStateWithLifecycle() used for the screen stateSay 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: and nit: in review comments.
  • Always explain why. "Use viewModelScope because it cancels with the ViewModel lifecycle" teaches; "use viewModelScope" does not.
  • Automate style with ktlint and detekt in 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 a Repository change should be split.
  • In Jetpack Compose, watch for remember scope errors, missing key parameters in LazyColumn, and LaunchedEffect that should be DisposableEffect for 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).
  • ktlintCheck comes from the org.jlleitschuh.gradle.ktlint plugin and detekt from the io.gitlab.arturbosch.detekt plugin; 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 large PR hid a Compose recomposition bug
  • A single PR added a new settings screen, refactored the UserViewModel, and changed the Repository interface.
  • 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 when userId changed.
  • The two-line mistake was easy to miss because it was buried among hundreds of changed lines across three layers.
The fix
  • 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 remember block reads is a key or is deliberately excluded" went on the review checklist, and reviewers tag such findings blocking:.
Nit-heavy reviews burned out reviewers
  • 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 ktlint or detekt gate in CI.
The fix
  • They applied the ktlint and detekt Gradle plugins (both hook into the check task) and made ./gradlew check a required CI step, with .editorconfig holding the formatting rules.
  • Reviewers agreed to label every comment blocking:, nit:, question: or praise:, 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: or nit: so the author knows what must change and what is optional.
  • Saying 'use X' without 'because Y'. A bare instruction teaches nothing. 'Use viewModelScope because 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 key in a LazyColumn or a wrong remember scope is easy to miss in a large diff. Split the PR or ask the author to.
  • No automated style gate. Without ktlint and detekt in 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 StateFlow here' 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

  1. 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.
  2. Read every comment. For each one, write a tag in the margin or a local file:
    • blocking – must fix before merge
    • nit – suggestion, author may skip
    • question – reviewer was unsure
    • praise – positive callout
  3. Count how many comments fall into each tag. Note the proportion that are nits.
  4. Pick the three most common nit comments. For each, name an existing ktlint or detekt rule (or .editorconfig setting) that would catch it automatically. If no rule exists, write a one-sentence team convention.
  5. Pick one blocking comment that lacked a "why." Rewrite it in two sentences: what is wrong, and why it matters (lifecycle, crash, leak, recomposition).
  6. 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.
Next: Writing design docs and ADRs