On the importance of code review

Source: Internet
Author: User
Tags version control system

"Editor's note" for Hugo Giraudel, the author discusses the importance of code review and how to implement it from various angles. The article is a domestic ITOM management platform OneAPM compiled rendering. The following is the text.

Recently, I saw this remark on Twitter:

Sadly, for many students, freelancers, and institutions, code censorship seems rather unfamiliar.

Obviously, the importance of code review is not well known to everyone. You can say I am naïve, but I do think that all IT companies are inseparable from the process. It's certainly not the case, it's a surprise to me.

In this article, I want to give an idea of the code review, and why I think it's a very important part of the code migration process, how to review it, and so on. If you are not currently reviewing code, or want to do better, hopefully this article will help you!

What is code review?

We live in the age of Wikipedia, so let's start by quoting the definition of code review:

Code review is a systematic test of a computer's source code (sometimes referred to as peer review). The goal is to find errors that are overlooked in the early stages of development, thus improving the overall quality of the software. There are various forms of review, such as pairing programming, informal walk-through, formal inspection and so on.

As the name implies, code review is a review of some code to ensure that it works properly and to improve its performance as much as possible.

Methods of code Review

As defined in Wikipedia, there are several ways to review code. However, too much code is present on GitHub, and code reviews are often accompanied by so-called pull request.

The pull request is a request to make changes to the code base using the Distributed version control System (Git, SVN, mercurial, and so on). It "pulls" the original code, writes the changes, and then submits the request to merge the changes.

Thanks to GitHub's friendly user interface, this process has become very simple and efficient, and GitHub outlines most of the git knowledge needs.

650) this.width=650; "src=" Http://blog.oneapm.com/zb_users/upload/2016/06/201606221466564478746085.png "alt=" On the importance of code review "title=" "style=" height:auto;vertical-align:middle;border:0px;/>

Why code Review is important

So, since we can do code migrations without any scrutiny and oversight, why is the code review so important? After all, we are capable of the job.

Theoretically, it is. In practice, however, there are many reasons to show the importance of code review. Let's take a look at a few of them.

Reduce risk

This is probably the most important reason. It is not trivial to have someone review our work, which can reduce the risk of neglected errors. After all, even good developers can be a momentary oversight.

And it's always necessary to make sure you don't forget anything. For example, front-end development often ignores the proper keyboard navigation, the usability of screen readers, the flexibility to adapt to internationalization, and the friendly non-JavaScript behavior, which only lists these four items.

Significantly improve code quality

Clearly, this is not just code standards and code checking (at least not all), but making the code more efficient.

In a team, everyone has their own backgrounds and strengths, and the team always needs to improve. So there are always people who might suggest smarter solutions, more appropriate design patterns, or ways to reduce complexity or improve performance.

Make everyone get better

By working together, everyone can learn from each other and make progress. The person submitting the code is likely to get feedback from the job and be aware of possible problems and parts that need improvement, and reviewers can learn new things by reading the code of others and find out what works for them.

Help familiarize yourself with the project

When a team is working on a project, it is extremely unlikely that each developer is committed to each part of the application. Sometimes this happens: at some point, a developer is working hard for most of the project's modules, while the other person is completely doing something else.

As a result, code reviews help people understand what others are writing, but they may need to maintain that code later. It facilitates the dissemination of code base knowledge within the team and may also accelerate future development.

How to properly conduct code review

Again, it is important to have a fixed code review process that is very useful. Whatever the method, the code created by each team should be reviewed in code.

That said, a meaningful code review is not as straightforward as it seems. However, don't worry, even if you do a bad job will not have any harm, is to waste some time.

Recently, my team reviewed the previous code review. When we realized that only 3 out of 12 developers were doing code reviews, we knew something was wrong.

To change this situation, one of our Scrum experts organized a retrospective analysis to determine the space that could be improved and how we would change it.

Planning ahead

Code censorship is not done enough, and the most common excuse for justifying it is that it takes time-others cannot or do not want to spend time on it.

I must say that I do not quite understand this argument, because my point is: If a colleague comes to me directly, let me help him, I will not say "I do not have the time, also not interested." Instead, I'll take the time to help, probably not now, after one hours--but obviously, I'm going to spend a few hours helping them. Why is it? Because:

    • This is the meaning of the team;

    • They asked me because they valued my opinion and it was worth my while to help them.

"Why don't you do code reviews?" ”
"I have no time." ”

For the author, the pull request is no different from my colleagues asking me for help. Sometimes it's acceptable to say you don't have the time, but systematically refusing to help others shows that you're actively trying to get yourself out of the team. This behavior is unfriendly and not positive. So be willing to take the time to provide help.

In order for developers to take the time, we began to consider allowing each programmer a little time (perhaps 30 minutes) to review the code every day. We don't get any surprises when we finish a half-hour code review every day: It's just a part of the day.

We've also tried to drastically reduce the amount of code included in pull request. Because there was a lot of pull request-there were thousands of changes in dozens of files.

We're trying not to do that now. By creating smaller pull request, it is easier to review code, feedback is more pertinent, and developers are more willing to participate in the process. "Code migration is smaller and more frequent."

Combining context

The second big problem we find is that we often lack the understanding of the code background, which is necessary if you want to provide useful feedback. Leaving the background of the code, we usually have only a grammar check-which, though useful to some extent, is far from enough. That's when you become what we call a "human reviewer."

Fortunately, this problem is better solved: Add a description to the pull request to explain your purpose and how to achieve it. This does not require a large paragraph of text, usually just a few lines enough. Adding links to and/or also works. Liv Madsen is one of our developers who even added screenshots--or related screencasts--to explain what she was doing, which was amazing.

650) this.width=650; "src=" Http://blog.oneapm.com/zb_users/upload/2016/06/201606221466564508724655.gif "alt=" On the importance of code review "title=" "style=" height:auto;vertical-align:middle;border:0px;/>

Actual Enquiry

The third problem is that sometimes we simply don't realize what we need to review. Indeed, we are flooded with countless e-mails and notifications every day-too many emails and so hard to keep. After all, we are just ordinary people.

Again, the solution is simple: ask someone directly about the code that needs to be reviewed. There are many ways to do this, such as asking a question in the office, or sending a message to your team's colleagues directly on the slack.

We created groups on GitHub based on our own activities and always ping a group when submitting pull request. Members of the group are notified and are free to choose how to resolve them whenever they have time. Sometimes, when a request is specifically directed at a particular (or a few) person's work, we ping the appropriate developer directly.

Then, the person who receives the ping message can review the code and post a comment. Even if there's nothing specific to report, we'll leave a message--that means the code can be merged.

Because we may not consider the existing comments and blindly merge some pull request, we have established a strict "reply or resolve" system. When you receive feedback, either you solve the problem or explain why you cannot resolve it in your reply. In any case, no outstanding comments can be left, and of course it cannot be combined with the pull request.

Summarize

Regular and efficient code reviews are essential for maintaining high-quality code standards, as well as knowledge sharing among developers and the development of teams.

Asking for code reviews doesn't mean you're weak, and asking someone for help isn't embarrassing, and the code review is certainly nothing to be ashamed of. On the other hand, accept the feedback you received and provide constructive (ideally, positive) comments to the person submitting the pull request.

Find the right job for you. The review code should be a significant part of the code migration process, so you should adjust it in a timely manner to ensure that it is beneficial to everyone.

Finally, I wish you all the pleasure to review the code!

This article is the OneAPM engineer to arrange the present. OneAPM can provide you with end-to-end application performance solutions, and we support all common frameworks and applications servers to help you quickly identify system bottlenecks and pinpoint the root cause of the anomalies. Minute-level deployments, instant experience, and performance monitoring have never been easier. To read more technical articles, please visit the OneAPM Official technology blog.

This article was transferred from OneAPM official blog

Original link: https://www.sitepoint.com/the-importance-of-code-reviews/


On the importance of code review

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.