2022/06/14 (增加連結)
Code Review通常是利用peer review,不過,因為工具的進步,也可以利用一些code analysis工具進行初步的code review。另外,Code Review要解決那些問題? 通常就是要尋找一些常見的程式問題 (code smell),讓我們的程式碼成為乾淨的程式碼 (clean code)。
如果團隊是第一次進行Code review,最好再進行之前,要對於code review的重點要有個共識。可以先從容易取得共識的部分開始,或者參考既有的coding style,要記得,很多的問題要循序漸進,否則,code review會成為團隊生產力的瓶頸,而不是助力。團隊對於程式要有比較明確的規範,或者透過review的過程形成規範。
當團隊裡有新成員時,首先也要讓新成員了解團隊的coding standard或者code review的重點,盡早啟動review,而且先從小範圍的review開始,不要等到寫了很多程式之後,才發現新成員完全沒有抓到重點而必須大幅的修改程式,另外,要記得review的重點是尋找一些常見的程式問題,讓我們的程式碼成為乾淨的程式碼,而不是菜鳥批鬥大會。
You are doing code reviews wrong
Level up your code reviews
Level 0 — Fully automated review
Level 0.5 — Automated review with human judgement
Level 1 — Pure readability review
Level 1.5 — Language readability review
Level 2 — Ownership review
Step 1: Give your team a demo
Step 2: Pick up the review
Step 3: Start the review alone
Step 4: Process Comments Together
Step 5: Solve Comments Together
Step 6: Automate Re-Occurring Remarks
Step 7: Validate Your Story
5 Ways Code Reviews Helped My Career
I Learned To Accept Constructive Criticism
I Learned How To Communicate Effectively With Other Teams
I Learned New Features of Programming Languages
I Learned To Appreciate Testing
Code Reviews Made Me Pay Closer Attention to the Little Things
Guide For An Effective Code Review
Here is a comprehensive list of checks we keep in mind during reviews.
Code Style Guide
Software Architecture
Software Design (SOLID)
Change Traceability
Documentation Coverage
New Developer On-boarding
The combination of all the above defines the effort needed for on-boarding a new developer.
Dependencies
Antipatterns
Maintainability
Extensibility
Reusability
Security
Performance
Scaleability
Usability
Testing Coverage
Automation Of Builds And Deployments
How to Review Code as a Junior Developer
Learning the code base
Building a feedback circle
Being an owner
How to Become a High-Quality Code Reviewer
Raise PR early
Raise simple PRs
Critique the code
Focus on the code, not the person. Critique code, and incorporate that mentality.
Involve experts
How one code review rule turned my team into a dream team
Rule 1: Each PR review must have at least 2 same-team developer approvals. Manager approval does not count.
Rule 2: Each PR must have a good description. From reading the description, the reviewer should be able to understand what the code is meant to do. This has to be true even if there is a Jira ticket or a requirements page.
Rule 3: PR must have sufficient unit test and integration test coverage.
Rule 4: If the PR is a bug fix, it must contain a test such that, should the bug fix be reverted, this test would fail.
Its not personal
Get to know your team
Ask questions
Provide context
Code Review Blog Post Series: Experiences and Lessons Learned Analyzing Code Review Practices
Structuring Your PR’s to Make Their Life Easy
Avoid massive change logs
Structure for comprehension
Short-circuit possible confusion
Provide enough context
Approaching a Teammate’s PR Efficiently and Effectively
Review in a timely manner
Gather context if it’s lacking
Start at a high level
Handling disagreements
Requesting changes
Empathy
3 Problems to Stop Looking For in Code Reviews
Issue 1: Checks that can be spotted by tooling
Issue 2: Problems with the overall approach
Issue 3: Pitfalls
13 Code Review Standards Inspired by Google
The code improves the overall health of the system
Quick code reviews, responses, and feedback
Educate and inspire during the code review
Follow the standards when reviewing code
Resolving code review conflicts
Demo UI changes as a part of code review
Ensure that the code review accompanies all tests
When focused, do not interrupt yourself to do code review
Review everything, and don’t make any assumptions
Review the code with the bigger picture in mind
Recognize and encourage good work during code review
Be mindful, respectful, kind, and clear in your code review
Explain your code review comments and keep scope in mind
How to Improve Your Code Reviews
Recipe for Code Reviews
Ingredients for the Author
The size of the changeset should be small
Proofread your diff
Ingredients for the Reviewer
Aim for improvement, not for perfection
Respect the scope of the review
The tone of the review
Review in a timely manner
Use a review checklist
7 tips for better Code Reviews
Be nice
Take the time to understand the underlying goal for the pull request
Provide suggestions for improvement. Show solutions rather than problems
Avoid stylistic, overly nit-picky comments
Don’t be afraid to check out the changes locally
Ask (open-ended) questions
Optimize for throughput, not for gatekeeping
5 Code Review Tips That You Can Use Right Away
Be Detailed in Your Explanations
Read the Description
Explain Your Reasoning
Ask Questions Rather Than Making Statements
Offer Compliments and Positivity
Always Share Your Thoughts
Understand the Acceptance Criteria (AC)
Keep Your Changes As Small as Possible
Make Team Standards Clear
Find Your Balance
How I Prevented a $3 Million Loss by Defining a Code Review Process
Seek to understand what your priorities are
Follow carefully the processes defined by the team
Understand the value behind your process
5 Things I Dislike the Most About Code Reviews
Opinionated Comment From the “I Am Always Right” Reviewer
Double Standard or a Standard That Keeps Changing
Repeated Comments for the Same Trivial Issue, but They Miss the Core Design/Structure Problem
Out-of-Scope Comments
Slow To Review and Respond
Iterate Faster With Automatic Code Review (github & probot)
2 Simple Tips to Increase Your Team Code Quality: Improve Your Team Code Review and Avoid Merge Conflict
ESLint
Prettier
一般而言,可以使用Code Analysis的工具來進行自動化的程式碼分析,程式碼分析有靜態分析以及動態分析,有幾個主要的重點:
靜態分析
統一寫作風格 (coding style)
找到安全漏洞
動態分析
分析程式的執行瓶頸
Code Refactoring (敏捷式軟體開發)
在CMMI裡,程序、文件及程式碼需要經過peer review,所以,code只是peer view的對象之一。code review的方法很多,但是,最常使用的方法就是peer review。
Peer Review
Level 1
PR 1.1 Perform reviews of work products and record issues.
Level 2
PR 2.1 Develop and keep updated procedures and supporting materials used to prepare for and perform peer reviews.
PR 2.2 Select work products to be peer reviewed.
PR 2.3 Prepare and perform peer reviews on selected work products using established procedures.
PR 2.4 Resolve issues identified in peer reviews.
Level 3
PR 3.1 Analyze results and data from peer reviews.