天天看点

【Google CodeReview 代码评审之道】如何处理审阅人的评论

如何处理审阅人的评论

当您发送了一个CL供评审时,评审人员很可能会对您的CL给出几个评论。下面是一些关于处理审阅者评论的有用信息。

不要认为这是针对个人的{#personal}

评审的目的是保持代码库和产品的质量。当一个评论家提供了代码的批判,认为它是试图帮助你,代码库,和谷歌,而不是人身攻击你或你的能力。

有时评论者感到沮丧,他们在评论中表达了这种沮丧。评论家这不是一个好的做法,但作为一名开发人员你应该做好准备。问问自己,“审稿人想要和我交流的有建设性的东西是什么?”

永远不要对代码评审评论做出愤怒的回应。这严重违反了职业礼仪,将永远存在于代码评审工具中。如果你太生气或生气而无法友好地回复,那么离开电脑一会儿,或者做点别的事情,直到你感到足够平静,可以礼貌地回复为止。

一般来说,如果一个评论者没有以建设性和礼貌的方式提供反馈,那就亲自向他们解释。如果你不能和他们面对面或视频通话,那就给他们发一封私人邮件。用一种友好的方式告诉他们你不喜欢什么,你希望他们做什么。如果他们也以非建设性的方式回应这个私人讨论,或者它没有预期的效果,那么根据情况升级到你的经理。

修复代码{# Code}

如果审阅人员说他们不理解代码中的某些内容,您的第一反应应该是澄清代码本身。如果无法澄清代码,则添加一个代码注释,解释为什么有代码。如果一条注释看起来毫无意义,那么只有在这种情况下,您才应该在代码评审工具中给出解释。

如果审阅者不理解您的代码,那么将来的其他代码读者也可能不理解。在代码审查工具中进行响应并不会帮助将来的代码阅读者,但是澄清你的代码或者添加代码注释会帮助他们。

为你自己想想

编写CL需要做很多工作。通常情况下,你会很满意自己终于完成了一份评估报告,并确信不需要再做更多的工作。当一个评论者带着可以改进的评论回来时,很容易条件反射地认为评论是错误的,评论者不必要地阻止了你,或者他们应该让你提交CL。无论你在这一点上多么确定,花一点时间回顾一下,考虑一下评审人是否提供了有价值的反馈,这将有助于代码库和谷歌。你的第一个问题应该是,“审查者正确吗?”

如果你不能回答这个问题,很可能审稿人需要澄清他们的评论。

你已经考虑过了,你仍然认为你是对的,你可以自由地回答为什么你的方法对代码库、用户和/或谷歌更好。嗯,评论者实际上是提供建议,他们希望你自己思考什么是最好的。实际上,您可能知道一些关于用户、代码库或CL的信息,而审阅人员并不知道这些信息。把它们填进去;给他们更多的背景。通常,您可以根据技术事实与审稿人达成一些共识。

解决冲突{#冲突}

解决冲突的第一步应该是与你的审稿人达成一致意见。如果您不能达成共识,请参阅代码评审标准,它给出了在这种情况下应该遵循的原则。

How to handle reviewer comments

When you've sent a CL out for review, it's likely that your reviewer will respond with several comments on your CL. Here are some useful things to know about handling reviewer comments.

Don't Take it Personally {#personal}

The goal of review is to maintain the quality of our codebase and our products. When a reviewer provides a critique of your code, think of it as their attempt to help you, the codebase, and Google, rather than as a personal attack on you or your abilities.

Sometimes reviewers feel frustrated and they express that frustration in their comments. This isn't a good practice for reviewers, but as a developer you should be prepared for this. Ask yourself, "What is the constructive thing that the reviewer is trying to communicate to me?" and then operate as though that's what they actually said.

Never respond in anger to code review comments. That is a serious breach of professional etiquette that will live forever in the code review tool. If you are too angry or annoyed to respond kindly, then walk away from your computer for a while, or work on something else until you feel calm enough to reply politely.

In general, if a reviewer isn't providing feedback in a way that's constructive and polite, explain this to them in person. If you can't talk to them in person or on a video call, then send them a private email. Explain to them in a kind way what you don't like and what you'd like them to do differently. If they also respond in a non-constructive way to this private discussion, or it doesn't have the intended effect, then escalate to your manager as appropriate.

Fix the Code {#code}

If a reviewer says that they don't understand something in your code, your first response should be to clarify the code itself. If the code can't be clarified, add a code comment that explains why the code is there. If a comment seems pointless, only then should your response be an explanation in the code review tool.

If a reviewer didn't understand some piece of your code, it's likely other future readers of the code won't understand either. Writing a response in the code review tool doesn't help future code readers, but clarifying your code or adding code comments does help them.

Think for Yourself {#think}

Writing a CL can take a lot of work. It's often really satisfying to finally send one out for review, feel like it's done, and be pretty sure that no further work is needed. So when a reviewer comes back with comments on things that could be improved, it's easy to reflexively think the comments are wrong, the reviewer is blocking you unnecessarily, or they should just let you submit the CL. However, no matter how certain you are at this point, take a moment to step back and consider if the reviewer is providing valuable feedback that will help the codebase and Google. Your first question to yourself should always be, "Is the reviewer correct?"

If you can't answer that question, it's likely the reviewer needs to clarify their comments.

Resolving Conflicts {#conflicts}