This is a general guideline for code reviewers. First of all, while it is great to add new features to a project, we must also be aware that each line of code we introduce also brings technical debt that we may have to eventually pay.
Open source code is maintained by a community with diverse background, and hence it is even more important to provide clear, documented and maintainable code. Code reviews are a shepherding process to spot potential problems, improve quality of the code. We should, however, not rely on the code review process to get the code into a ready state. Contributors are encouraged to polish the code to a ready state before requesting reviews. This is especially expected for code owner and committer candidates.
Here are some checklists for code reviews, it is also helpful reference for contributors.
The first rule for code reviewers is to always keep the highest standard, and do not approve code just to “be friendly”. Good, informative critics each other learn and prevent technical debt in early stages.
A minimum and stable API is critical to the project's life. A good API makes a huge difference. Always think very carefully about all the aspects including naming, argument definitions and behavior.
When possible, pay more attention still to the proposed API design during code reviews. Remember, it is easier to improve code implementation, but it is extremely hard to change an API once accepted. We should treat data structures that are shared across modules(e.g. AST) in the same way. If/when uncertain, start a conversation with more developers before committing.
Here are some useful principles for designing APIs:
Each new change of features should introduce test cases. Bug fixes should include regression tests that prevent the problem from happening again.
Documentation is often overlooked. When adding new functions or changing an existing function, the documentation should be directly updated. A new feature is meaningless without documentation to make it accessible. See more at [Write Document and Tutorials]({% link pages/community/document.md %}).
Always be cautious in introducing dependencies. While it is important to reuse code and avoid reinventing the wheel, dependencies can increase burden of users in deployment. A good design principle is that a feature or function should only have a dependency if/when a user actually use it.
While it is hard to implement a new feature, it is even harder to make others understand and maintain the code you wrote. It is common for a PMC or committer to not be able to understand certain contributions. In such case, a reviewer should say “I don't understand” and ask the contributor to clarify. We highly encourage code comments which explain the code logic along with the code.
Some basic principles applied here: favor vectorized array code over loops, use existing APIs that solve the problem.
When you find there are some common or recurring lessons that can be summarized, add it to the [Code Guide and Tips]({% link pages/community/code_guide.md %}). It is always good to refer to the guideline document when requesting changes, so the lessons can be shared to all the community.
The code reviewers and contributors are paying the most precious currency in the world -- time. We are volunteers in the community to spend the time to build good code, help each other, learn and have fun hacking.
There can be multiple reviewers reviewing the same changes. Many times other reviewers may spot things you did not find. Try to learn from other code reviews, when possible, document these lessons.
The contributor and code owner can request code reviews from multiple reviewers. Remember to approve changes when your comments are addressed in a code review. To do so -- please click on changes tab in the pull request, then select approve, or comment on the code and click request changes. Code owner can decide if the code can be merged in case by case if some of the reviewers did not respond in time(e.g. a week) and existing reviews are sufficient.
Checkout the following PRs that need review"