Hello.
In this lesson we'll learn basics of code review process.
We'll start the lesson from learning the basic principles and goals of code reviews.
I will explain you what different types of code reviews exist and which type is recommended for you
under which circumstances.
Today we'll review in details such fundamentals as rules of code, reviewer and author.
I will also explain you what the reviewer mindset is and how to develop it.
And by the end of the lesson, we'll talk about strategies for efficient code review.
Let's start our lesson.
And as I mentioned in agenda of the lesson, let's start from learning basic principles of code review
process.
On this stage, it is super important to create solid basement for our future learning.
Basic principles are.
Collaboration.
Feedback.
Continuous improvement.
Focus on objectives.
Code standards.
Code ownership.
Automation.
Timeliness.
Documentation.
Let's review them one by one.
Code review involves multiple team members collaborating to review each other's code.
It promotes knowledge sharing and spreads best practices.
Code review encourages discussions about design decisions, code structure, and potential improvements,
leading to better informed decisions and more effective teamwork.
Provide constructive feedback that helps the author improve their code.
Feedback should be specific, actionable, and respectful.
Code review is an iterative process aimed at continuously improving code quality.
It is about learning and growing as a team.
Code review encourages developers to reflect on their coding practices and seek opportunities for optimization
and refinement.
Reviewers should focus on the objectives of the code change, such as solving a particular problem or
implementing a new feature, rather than nitpicking on tribal issues.
This is important ensures that code adheres to the team's coding standards, style guidelines, and
best practices.
Consistency is crucial for maintainability and readability.
Respect the authors ownership of their code while also promoting collective code ownership.
Encourage authors to take responsibility for their code and address feedback accordingly.
Use automated tools such as linters and static code analysis tools to catch common issues and enforce
coding standards.
This helps streamline the review process and ensures consistency.
Conduct code reviews in a timely manner to avoid delays in the development process.
Set clear expectations for review turnaround times, and prioritize critical changes.
Document decisions made during the review process, especially regarding design choices, architectural
decisions, and lessons learned.
This helps maintain a record of discussions and facilitates onboarding of new team members.
The basic principles of code review process.
Let's review now.
Goals of code review process.
There are following goals of code review process quality assurance.
Knowledge sharing, consistency, risk reduction, code ownership, onboarding and mentoring.
Let me explain you each of these.
Ensure the quality of the code base by identifying and fixing defects, bugs, and potential issues
before you find them in production.
Code review helps in maintaining a high level of code quality, which ultimately leads to better software
reliability and user satisfaction.
Facilitate knowledge sharing among team members by providing an opportunity for developers to learn
from each other through code review.
Team members can gain insights into different coding styles, techniques, and approaches, thus improving
their own skills and understanding of the code base.
Enforce coding standards, best practices, and design patterns across the code base by reviewing code
changes.
Teams can ensure consistency in coding style architecture and implementation, making the code base
more maintainable and easier to understand for everyone.
Mitigate the risk of introducing defects and vulnerabilities into the code base by having multiple sets
of eyes.
Reviewing code changes.
Teams can catch potential issues early in the development process, reducing the likelihood of costly
bugs slipping into the production.
Foster a sense of ownership and accountability among team members by participating in code review.
Developers take responsibility for the quality and integrity of their code, leading to a more empowered
and motivated team.
Facilitate the onboarding process for new team members by exposing them to the code base and development
practices through code review.
Additionally, Code Review serves as a platform for more experienced developers to mentor junior members,
helping them grow and develop their skills.
Overall, the primary goals of the code review process are to improve code quality, foster collaboration
and learning, mitigate risks, and ultimately deliver better software products to users.
And now let's review different types of code reviews.
There are several types of code reviews, each with its own characteristics and objectives.
Here are some common types.
Pair programming.
In pair programming.
Two developers work together at the same workstation.
They collaboratively write and review code in real time, discussing design decisions and implementation
details as they go.
Pair programming fosters close collaboration and immediate feedback, leading to higher code quality
and knowledge sharing.
I used to work using pair programming technique.
My personal feedback is this is simply amazing, but sometimes better quality is not instantly visible,
and sometimes it is challenging to explain business stakeholders why two people are working on the same
task.
Because usually business stakeholders think in a straightforward way.
If there are two developers, they can produce twice as much code, so no sense for them to work in
pairs.
So, you know pros and cons.
And it is only matter of your decision now and how you will explain this to business stakeholders.
If you would have any questions, please do not hesitate to post your questions below the video and
I will be happy to answer.
Another type of code review is ad hoc reviews.
AD hoc reviews are informal and spontaneous code reviews that occur on an as needed basis.
Developers may request feedback from their colleagues or spontaneously review each other's code without
following a structured process.
While less formal, ad hoc reviews can still provide valuable insights and help identify issues early
in the development process.
Over the shoulder reviews.
Over the shoulder reviews involve one developer physically sitting with another and reviewing their
code.
The reviewer provides feedback and suggestions in real time as they examine the code together.
Over the shoulder reviews are beneficial for immediate feedback and knowledge transfer, but may not
be practical for remote or distributed teams.
Tool assisted reviews.
Tool assisted reviews utilize specialized code review tools or platforms to facilitate the review process.
These tools offer features such as code diffing to highlight all differences instantly, inline commenting,
issue tracking, and workflow management to streamline the review process and enhance collaboration.
Example of code review tools include GitHub, GitLab, Bitbucket, and others.
Formal inspections.
Formal inspections, also known as peer reviews or walkthroughs, are structured and thorough code review
processes conducted according to predefined guidelines and checklists.
Participants typically include developers, testers, and other stakeholders who systematically examine
the code for defects, compliance with standards, and adherence to requirements.
Formal inspections are more time consuming, but can be highly effective for identifying complex issues
and ensuring high quality code.
Synchronous code review.
In this type, the coder produces the code independently and then reviews it immediately, with the
reviewer discussing and improving the code together.
It is useful when the reviewer lacks knowledge about the task goals or when extensive code improvements
are expected.
Asynchronous code review.
Here, the coder completes the code and makes it available for review.
The reviewer then reviews the code at their own pace, providing commands and suggestions asynchronously.
This type is beneficial when there is no direct dependency between the code and the reviewer, and allows
for flexibility in scheduling.
Asynchronous code review can be done with assistance of different tools for code review.
Code review.
Once in a while, this method involves periodic code review sessions conducted by the entire team,
where one developer presents a piece of code they have been working on, and the team collectively reviews
and discusses it.
While not a permanent option, it can be useful for teams new to code reviews.
Each type of code review has its own strengths and weaknesses, and the choice of which to use depends
on factors such as team size, project complexity, development methodology, and organizational culture.
Combining different types of code, reviews can provide a comprehensive approach to code quality assurance
and collaboration within software development teams.
When selecting the type of code review to use, several factors should be considered to ensure that
it aligns the team's goals, workflow, and project requirements.
So, how to select the type of code reviews that will suit your team's best?
Let me provide you with a more detailed explanation of when to choose each type.
Asynchronous code reviews.
Asynchronous code reviews are suitable as a default option for professional development teams due to
their flexibility and efficiency.
They allow developers to review code at their own pace without being tied to synchronous collaboration.
Asynchronous reviews prevent the need for force context switching, where developers are interrupted
from their current tasks to participate in a review session.
This helps maintain focus and productivity.
Asynchronous reviews are effective for most common use cases, where developers can review code independently
and provide feedback asynchronously.
This type is ideal for teams with diverse schedules and distributed members.
Synchronous code reviews are appropriate when the reviewer lacks understanding of the changes made by
the coder.
In such cases, immediate collaboration and explanation can help clarify the code and ensure that feedback
is relevant and accurate.
If extensive code improvements are expected due to the coders lack of experience or familiarity with
the task.
Synchronous reviews allow for real time discussion and iteration on the code.
This can accelerate the review process and ensures that improvements are made efficiently.
Pair programming or instant code review is beneficial when solving complex business problems that require
close collaboration and immediate feedback to developers.
Working together can brainstorm solutions, discuss edge cases, and ensure that all scenarios are properly
handled in the code.
Pair programming works best when both developers have similar levels of expertise, allowing them to
work at a consistent pace and effectively collaborate on problem solving.
It fosters mutual learning and motivation, leading to higher productivity and code quality.
So asynchronous code reviews are the recommended default option for professional development teams due
to their flexibility and efficiency.
Synchronous reviews are.
Pair programming can be utilized when necessary, such as when immediate collaboration is required,
or for solving complex business problems.
Ultimately, the choice of code review type should be based on the specific needs and circumstances
of the team and the project.
Understanding the roles of both the code reviewer and the code author is crucial for an effective code
review process.
Here is an explanation of each role.
Code reviewer.
The code reviewer is responsible for evaluating the code changes submitted by the author.
This involves examining the code for errors, bugs, readability issues, and adherence to coding standards.
The reviewer provides constructive feedback to the author based on their evaluation of the code.
Feedback should be specific, actionable, and respectful, aimed at helping the author improve the
quality of their code.
Reviewers often share their expertise and knowledge with the author during the review process.
They may suggest alternative solutions, best practices, or improvements based on their experience
and understanding of the code base.
In some cases, the reviewer acts as a gatekeeper insurance that only high quality code is merged into
the code base.
They may reject code changes that do not meet the required standards, or pose risks to the stability
and integrity of the software.
Reviewers collaborate with the author to discuss and address issues identified during the review.
This collaboration fosters communication, teamwork, and collective ownership of the code base.
Let's now talk about code author role.
The code author is a developer who wrote the code changes being reviewed.
They are responsible for implementing the requested feature, fixing bugs, or making improvements to
the code base.
The author presents the code changes to the reviewer for evaluation and feedback.
They may provide context, explanations, or documentation to help the reviewer understand the purpose
and intent of the changes.
Authors receive feedback from the reviewer and are expected to consider it seriously.
They should be open to constructive criticism and willing to make necessary revisions to improve the
quality of their code.
Authors use code reviews as an opportunity to learn and grow.
As developers, they gain insights into the best practices, coding standards, and areas for improvement
through feedback provided by reviewers.
Ultimately, the author is responsible for addressing issues identified during the review and ensuring
that their code meets the required standards and quality criteria.
They may need to make revisions, clarify requirements, or seek assistance from other team members
as needed.
Let's now talk about development of a reviewer mindset.
Developing a reviewer mindset is essential for conducting effective code reviews.
Let's review some key aspects to consider when growing this mindset.
Pay close attention to the details of the code being reviewed.
Look for syntax errors, logic flaws, performance issues, and adherence to coding standards.
A keen eye for detail helps ensure that no potential issues go unnoticed.
Approach the review process with a critical mindset.
Question assumptions, challenge design decisions, and look for alternative solutions.
Critical thinking helps identify weaknesses in the code and suggests improvements that enhance its quality
and robustness.
Put yourself in the shoes of the code author and consider their perspective.
Understand the challenges they faced, the constraints they worked under, and the reasons behind their
decisions.
Empathy fosters constructive feedback and promotes a supportive and collaborative review environment.
Effectively communicate your feedback to the code author.
Clearly articulate your thoughts, suggestions, and concerns in a respectful and professional manner.
Use descriptive language.
Provide examples, and offer explanations to ensure that your feedback is understood and actionable.
Be open to different ideas, approaches and solutions presented in the code being reviewed.
Avoid being overly attached to your own preferences or biases.
Embrace diversity of thought and welcome feedback from others, even if it challenges your own perspective.
Approach each code review as an opportunity to learn and grow as a developer.
Stay curious, ask questions, and seek to expand your knowledge and understanding of different programming
languages, frameworks, and design patterns.
Embrace feedback from others as a means of personal and professional development.
Advocate for code quality and best practices within the team.
Encourage adherence to coding standards.
Consistency in coding style and adoption of software engineering principles.
Support initiatives that promote code quality such as code refactoring, automated testing, and code
reviews.
Be patient and respectful towards the code author during the review process.
Recognize that everyone makes mistakes and that code reviews are meant to improve, not criticize.
Offer feedback in a constructive and supportive manner, focusing on the code rather than the individual.
By embracing these principles and adopting a reviewer mindset, you can become an effective code reviewer
who contributes to the overall quality and success of the software development process.
And now it is time to review code review strategies in order to make a code review process even more
efficient.
Efficient code review requires careful planning, effective communication, and streamlined processes.
Let's review some strategies to conduct efficient code reviews.
Define the goals and expectations of the code review process up front.
Clarify what aspects of the code need to be reviewed, such as functionality, readability, performance,
and adherence to coding standards.
Develop and communicate clear guidelines for code reviews, including criteria for evaluating code quality,
standards for coding style and formatting, and expectations for reviewer and author behavior.
Consistent guidelines help ensure that reviews are focused and productive.
Take advantage of automated tools and utilities to streamline the review process.
Use code Linters, static analyzers and continuous integration systems to catch common issues and provide
feedback automatically.
This reduces the manual effort required for review and ensures consistency in code quality.
Break down large code changes into smaller, manageable chunks that can be reviewed independently.
This makes it easier for reviewers to focus on specific aspects of the code and provides more granular
feedback.
It also reduces the risk of overwhelming reviewers with too much information at once.
Prioritize code reviews based on factors such as impact of the change, the urgency of the task, and
the expertise of the reviewers.
Focus on reviewing critical or high risk changes first to minimize the potential for bugs and issues
to slip through.
Set limits on the size and scope of code changes to be reviewed in each session.
Aim for reviews that can be completed within a reasonable amount of time, such as 30 minutes to an
hour.
This helps maintain focus and prevents fatigue and burnout among reviewers.
Encourage developers to perform self reviews of their code before submitting it for review.
This allows authors to catch and address common issues and mistakes on their own, reducing the burden
on reviewers and accelerating the review process.
Provide timely feedback to authors during the review process.
Avoid unnecessary delays in reviewing code changes, as this can lead to bottlenecks and prolong the
development cycle.
Aim to review code changes promptly and provide feedback within a reasonable time frame.
Foster a collaborative environment where reviewers and authors can discuss code changes openly and constructively.
Encourage open communication, active participation, and mutual respect among team members.
Collaboration leads to better understanding, alignment, and ultimately higher quality code.
Continuously validate and refine the code review process based on feedback and lessons learned.
Ask for an input from team members on ways to improve efficiency, effectiveness, and overall satisfaction
with the review process.
Adapt and iterate on your strategies to ensure that code reviews remain valuable and productive over
time.
By implementing these strategies, teams can conduct efficient and effective code reviews that improve
code quality, promote knowledge sharing, and foster collaboration within the development team.
That's all.
What I wanted to share with you today.
Let's recap what we have learned in the lesson.
In this lesson, we have learned a lot.
We learned basic principles and goals of code review.
I explained you different types of code review, and I explained what types of code review are applicable
in which case.
We learned role of code reviewer and author.
I shared with you guidelines that will help you to develop reviewer mindset.
And at the end of the lesson we learned strategies for efficient code review.
And just to remind you that in case you have any questions, please do not hesitate to post your questions
below the video and I will be happy to answer.
That's it for this lesson.
Thanks a lot for your attention.
Have a great day and see you in the next lesson.