- Software Development General Best Practices
- Defensive Programming / Application Security Best Practices
I have collected some points and created this list for PR and Code reviews. I intend to refer to this post frequently to help me become a better reviewer.
- Organizations with good code reviews ensure that all engineers take part in the code review process
- Good code reviews use the same quality bar and approach for everyone, regardless of their job title, level, or when they joined the company.
- Better code reviews pay additional attention to making the first few reviews for new joiners a great experience. Reviewers are empathetic to the fact that the recent joiner might not be aware of all the coding guidelines and might be unfamiliar with parts of the code. Provide relevant documentation (guidelines, style guides, etc) to help engineer improve their code.
- Ensure no code makes it to production without a code review
- PR and reviews should be time-bound. Ensure that PRs get reviewed, approved/rejected within a scrum cycle to avoid stale code
- Foster a good code review culture in which finding defects is viewed positively, Give respectful and constructive feedback
- Prioritize Review Over Coding
- Integrate code review into your daily routine
- Review at least part of the code, even if you can't do all of it
- Review fewer than 400 lines of code at a time
- Take your time while reviewing someone else's code, do not depend on others to catch errors
- Do not bunch PRs for review. Instead, scatter reviews tasks throughout the working hours
- Ensure the PRs comes with tests
- Build and Test — Before Code Review
- Ensure external documents if any (API, user manual, etc.) are updated
- Give Feedback That Helps (Not Hurts)
- Create and follow a code-review checklist.
- While reviewing code, be mindful about the following:
- Security best practices
- Manageability (Readability, structure, style)
- Maintainability (Logic, Test Coverage)
- Correctness (Functionality)
- Invalid input/states
- Usability (Performance)
- Object-Oriented Analysis and Design (OOAD) Principles
- Verify that the defects if any -are actually fixed
- PR Rejections must always include a better explanation for why the PR got rejected
- There are various git workflow, get yourself acquainted with different git workflows: https://www.atlassian.com/git/tutorials/comparing-workflows
- You should annotate PRs with self-explaining comments before the review
- Create Small Change Lists, Change Lists Should Be Complete on Their Own
- Never self-approve a PR, always ask your peers for approval after code review
- Before opening a PR, make sure you squash all your commits into one single commit using git rebase (squash). Instead of having 50 commits that describe 1 feature implementation, there must be one commit that describes everything that has been done so far.
- Prior to making PRs always check to see you have merged the most updated code from the master branch. Update all affected tests and or create new tests for files you changed.
- Do not push any code with runtime errors thrown by dependencies or source code. When one appears, you should fix that bug ASAP—even if everything else seems to be running ok. There’s a reason that error was thrown, so fix it and don’t leave it for someone else to worry about it.
- Remove all unnecessary console logs prior to making a PR
☐ Unit Test provided
☐ Deprecated code removed
☐ Syntax & Formatting is correct (Linting should help with this)
☐ Is the approach to the problem appropriate?
☐ Can anything be simplified?
☐ Is the code too specific to the product and needs generalization?
☐ Do forms need to sanitized
☐ Any obvious security flaws or potential holes
☐ Are the naming conventions appropriate?
☐ Are there enough comments inline with the code?
☐ Is there documentation needed?
☐ Is there anything included that should not be?
☐ Are all dependencies declared?
☐ Are there any code smells? https://blog.codinghorror.com/code-smells/
NOTE: If you want to update this list, please comment, I'll incorporate your changes.