Code Review Guide

原创
2018/04/30 10:47
阅读数 140

前几天看Tidb的github项目,无意中看到他们的code review guide, 觉得写得不错,但是是英文的,索性拿过来翻译下,以后自己做code review的时候也可以反省下。

Code Review Guide 代码评审指南

Things to do before you start reviewing the PR 在review代码之前需要做什么?
  • Make sure you are familiar with the packages the PR modifies. 确认熟悉此PR所修改的packages

  • Make sure you have enough continuous time to review the PR, use 300 LOC per hour(1小时300行代码?) to estimate 确认有足够连续的时间来review。用1小时300行代码的标准来度量

  • Make sure you can follow the updates of the PR in the next few work days. 确认接下来的几个工作日你能跟踪此PR的更新

  • Read the description of the PR, if it's not easy to understand, ask the coder to improve it. 读一读此PR的描述,如果难以理解,请coder来完善它

  • For a bug fix PR, if there is no test case, ask the coder to add tests. 对于fix bug的PR, 如果没有提供测试用例,请coder来添加该用例。

  • For a performance PR, if no benchmark result is provided, ask the coder to add a benchmark result. 对于性能相关的PR, 如果没有提供基准测试,请coder来加基准测试结果

Things to check during the review process 评审过程中需check的地方
  • Am I able to understand the purpose of each unit test? 想想自己能理解每个单元测试的目的吗

  • Do unit tests actually test that the code is performing the intended functionality? 单元测试实际上测试了代码想要实现的功能了吗

  • Do unit tests cover all the important code blocks and specially handled errors? 单元测试覆盖了所有重要的代码块了吗,特别是错误处理这一块?

  • Could procedure tests be written to table driven tests? xxxxxx这个貌似用不着

  • Is the code written follwing the style guide? 代码编写是否符合代码风格规范?

  • Is the same code duplicated more than twice? 有没有冗余代码?

  • Do comments exist and describe the intent of the code? 有没有注释或者代码意图的描述

  • Are hacks, workarounds and temporary fixes commented? xxxxxxx没看懂

  • Does this function do more than name suggests? 函数名与函数功能的统一

  • Can this function's behavior be inferred by its name? 由函数名推测出函数行为

  • Does tests exists and are the comprehensive? 有没有测试,是否全面?(这个是不是跟覆盖率重了?)

  • Do unit tests cover all the important code branches? 关于分支的

  • Could the test code be extracted into a table-driven test?

Things to keep in mind when you are writing a review comment 写评审的时候需要想写什么
  • Be kind to the coder, not to the code. 对程序员好点,对代码坏点,哈哈哈

  • Ask questions rather than make statements. 以问题的形式而不是说明的形式

  • Treat people who know less than you with respect, deference, patience. 待人以尊重、顺从、耐心

  • Remember to praise when the code quality exceeds your expectation. 超出预期要表扬

  • It isn't necessarily wrong if the coder's solution is different than yours. 与自己想的不一样,但不一定是错的

  • Refer to the code style document when necessary. 需要时查看代码规范

Things to remember after you submitted the review comment 提交评审后要记住的事情
  • Checkout Github notification regularly to keep track of the updates of the PR. 定期检查github的通知,方便跟踪PR的更新

  • When the PR has been updated, start another round of review or given it a LGTM. PR更新之后开始新一轮的评审

展开阅读全文
加载中

作者的其它热门文章

打赏
0
0 收藏
分享
打赏
0 评论
0 收藏
0
分享
返回顶部
顶部