一盏灯
首页文章视频生词本复习
首页文章视频生词本我的

Code Review Comments That Don't Hurt

不伤人的代码评审意见

科技互联网模板范文中级约 4 分钟场景 · code review# 邮件与写作# 管理与领导力

同样一条评审意见,措辞不同,收到的是感谢还是敌意。这份模板给出四类高频评审场景的写法:指出 bug、建议更优写法、追问设计意图、给出必须改的阻断项。核心套路是——评论代码而非评论人、用『我们/这段代码』代替『你』、给出理由和示例、把主观偏好和必须修改分清楚,并且不吝啬真诚的表扬。会写评审意见,是资深工程师的软实力。

当前浏览器暂不支持语音朗读

A code review is a technical act, but it is read as a personal one. The same fix suggested two ways can land as helpful mentoring or as a public jab. Written comments have no tone of voice, so the reader supplies one — usually the harshest reading. This playbook gives you four templates for the most common review situations. The throughline is simple: comment on the code, never on the coder, and always say why.

代码评审是一件技术活,但它会被当成一件私人的事来读。同一个修改建议,两种写法,收到的可能是被善意指导的感觉,也可能是当众挨了一拳。书面评论没有语气,于是读者会自行脑补一个——通常是最刺耳的那种解读。这份手册给你四个最常见评审场景的模板。贯穿始终的原则很简单:评论代码,而绝不评论写代码的人,并且永远说明为什么。

"I think there might be a bug here: if `items` is empty, this line divides by zero and the request will crash. Could we add a guard for the empty case? Something like an early return when `items.length === 0` would do it."

『我觉得这里可能有个 bug:如果 items 为空,这一行就会除以零,请求会崩掉。我们能不能为空的情况加一个防护?比如在 items.length === 0 时提前 return,应该就可以了。』

Use this when you spot a real defect. Notice three moves: "I think" softens the claim without hiding it, the explanation says exactly what breaks and when, and the suggestion offers a concrete fix instead of just naming the problem. "This is broken" starts a fight; "if items is empty, this divides by zero" starts a fix. Point at the code and the failing case, never at the author's carelessness.

当你发现一个真实缺陷时用这个。注意三个动作:『我觉得』在不掩盖问题的前提下软化了断言;解释清楚说明了到底什么会坏、在什么时候坏;而建议给出的是一个具体的修法,而不只是点出问题。『这里坏了』会挑起一场架;『如果 items 为空就会除以零』会开启一次修复。把矛头对准代码和会出错的场景,绝不对准作者的粗心。

"This works, and I would ship it as is if we are in a hurry. One optional idea for later: we could replace the nested loops with a lookup map, which would drop this from O(n²) to O(n). Totally your call — not a blocker."

『这段能跑,如果我们赶时间,我照原样合并也没问题。给以后留一个可选的想法:我们可以把嵌套循环换成一个查找表,这样复杂度能从 O(n²) 降到 O(n)。完全由你决定——不是阻断项。』

Use this for improvements that are nice but not required. The magic words are "optional," "your call," and "not a blocker": they make crystal clear that the author can decline without any drama. Separating preference from requirement is the single most trust-building habit in review. When reviewers dress up every personal taste as a mandate, authors start ignoring all of it. Label the small stuff as small, and your real objections get taken seriously.

对那些锦上添花、但并非必需的改进用这个。关键词是『可选』『由你决定』和『不是阻断项』:它们清清楚楚地表明,作者可以毫无心理负担地拒绝。把『偏好』和『要求』分开,是评审中最能建立信任的一个习惯。当评审者把每一个个人口味都包装成命令时,作者就会开始对全部意见充耳不闻。把小事标注成小事,你真正的反对意见才会被当回事。

"Help me understand the reasoning here — I might be missing context. Why do we cache the token in memory instead of reading it fresh each time? If there is a performance reason I will happily drop this, I just want to make sure we are not risking a stale token after a refresh."

『帮我理解一下这里的思路——我可能缺少上下文。我们为什么把 token 缓存在内存里,而不是每次都重新读取?如果是出于性能考虑,我很乐意收回这条,我只是想确认我们不会在刷新之后冒着 token 过期的风险。』

Use this when you suspect a problem but are not sure — which is often. Asking a genuine question does two things at once: it gives the author room to explain a decision you may have misjudged, and it surfaces a real risk if there is one, without accusing anyone. "Why did you do it this way?" can sound like an attack; "help me understand — I might be missing context" invites a conversation. Curiosity ages far better than certainty in a review thread.

当你怀疑有问题、却又拿不准时用这个——而这种情况很常见。提一个真诚的问题一举两得:它给作者留出空间去解释一个你可能误判了的决定,同时,如果确实存在真实风险,也能把它摆出来,又不指责任何人。『你为什么这么做?』听起来可能像攻击;『帮我理解一下——我可能缺少上下文』则是在邀请一场对话。在评审的讨论串里,好奇心远比笃定更经得起时间检验。

"This one I do need us to change before merge: the API key is hard-coded on line 42, which would ship a secret to the public repo. Let's move it to an environment variable. Happy to pair on it if that is quicker. Everything else looks great — the error handling in this PR is genuinely clean."

『这一条我确实需要我们在合并前改掉:第 42 行硬编码了 API 密钥,这会把一个机密推到公开仓库里。我们把它挪到环境变量里吧。如果结对更快,我很乐意一起弄。其余部分都很棒——这个 PR 里的错误处理是真的干净。』