Code RevIEW
Best Practices



Code Review
What is Code Review
Code reviews are methodical assessments of code designed to identify bugs, increase code quality, and help developers learn the source code.
GitLab

main goal of CODE REVIEW
code review ACTORs
Author: who writes the code.
Reviewer: who reads the code and decides when it’s ready to be merged into the team’s codebase.
Changelist: a set of changes to source code that the author wants to merge.
Rounds: complete round-trip between the author and reviewer.
Approvers: green light reviewers.

1
Share knowledge
- Transfer codebase knowledge, solution approaches, and quality expectations between actors.
2
Discover bugs earlier
- Improve code quality: readability, performance, security, scalability.
3
Maintain compliance
- Use clear guidelines and standards.
- Coding style, formatting, documentation etc.
5
Increase collaboration
- Find the most effective solutions.
- Feel more ownership and a stronger sense of belonging.
4
Automated Checks
- Maintain code quality.
- Reduce manual effort.
CODE REVIEW BENEFITS
After
- The Requirement supplies the definition of done.
- Automated checks.
When should happen?
Before
- The code merges into the repository’s mainline branch.
But
Should happen
Let computers do the boring parts
Whitespaces, indentations, Styling, Automated Test, Unused variables, Formatters, Builds etc...
Use CI/CD servers.
How is the Code Review Process?
How to request a Code Review
Code reviews should be easy to review so as not to waste reviewers' time and motivation.
How to do a code review


- What should we review?
- How to give feedback?
1
Scope and size
The changes should have a narrow, well-defined, self-contained scope
2
Only submit complete, self-reviewed, and self-tested Pull Requests.
3
Automate as much as possible
- Automated tests.
- Code builds.
- Code style.
- Identify unused code.
5
Add as much context as possible
Add the ticket, description, possible breaking changes, add labels, reviewers and assignees.
4
Follow Git Guidelines
- Branching strategy.
- Commit messages.
- Pull Request templates.
6
Find the reviewers
- Tag the dev team.
- Send the PR through Slack.
- DM the ones who are familiar with the codebase
HOW TO request a code review


Scope and size
HOW TO request a code review

Follow Git Guidelines

HOW TO request a code review
Be open to feedback
Code reviews are classless
Being the most senior person on the team does not imply that your code does not need review.


HOW TO request a code review
1
Purpose
- Does this code accomplish the author’s purpose?
- Ask questions.
2
Legibility and style
- Consistent coding style and naming convention.
- Enforce compact code.
3
Implementation
- Think about how you would have solved the problem.
- Do you see potential for useful abstractions?.
5
Give Constructive Feedback
- Use we instead of you.
- Be polite.
- Use principles instead of opinions. Provide evidence.
- Highlight the good.
- Be assertive.
- Use examples.
4
Maintainability
- Ask for tests.
- Check breaking changes.
- Check the Docs (README, CHANGELOG)
6
Pair Programming FTW
- Two heads are better than one.
- Share knowledge and mutual learning.
HOW TO DO a code review


Source: https://mtlynch.io/human-code-reviews-1/
Legibility and style
HOW TO DO a code review



HOW TO DO A CODE REVIEW

Add context

Use the GitHub Files Tree
HOW TO DO A CODE REVIEW

Use the viewed button
HOW TO DO A CODE REVIEW
Be generous with examples

HOW TO DO A CODE REVIEW

Comment, Approve or Request Changes

FOSTER A POSITIVE
Code Review CULTURE
Let's do it 🔥
Code review provides an opportunity for mentorship and collaboration.
Code review process diversifies the understanding of code in the codebase.
Why is IT important?
Return on Investment (ROI)
- Avoid delivery defects.
- Optimize developers time.
- Increase productivity.
- Increase maintainability.
- You will learn.
Sources
Code Review Best Practices
By Juan Sebastián
Code Review Best Practices
- 314