当前位置:网站首页>CR2

CR2

2020-12-06 10:38:35 Mujiutian

Code Review Translated into Chinese is code review , The specific definition can be seen in  wiki. This article wiki said Code Review It's a huge help in helping the team find code defects :“ Code reviews can generally find and remove about 65% Error of , Up to 85%”. actually , Code Review It's a lot more than that , It can help us in at least three ways :

  1. To spread knowledge .

I believe many people submit for the first time Code Review Have similar experiences : A few hundred lines of code , But dozens of them have been mentioned comments, More than a dozen code updates , Before they were finally accept . In fact, when the code is accept, The engineer who submitted the code passed this review I learned about code specifications and a lot of good practices . meanwhile , adopt review More senior engineer's code , Young engineers also learn architecture and coding more intuitively ; in addition , Engineers can also use review Code to share project knowledge , Looking at code implementation is the best way to understand a project most of the time .

2、 Improve code quality .

It's also easy to understand , Experienced engineers can design in Architecture 、 Code details and other aspects to help beginners . Different engineers also have knowledge blind spots , each other review And progress is fast . in addition , By review There is also a psychological factor that many people don't notice : In a bad situation , It is inevitable that engineers will rush to write “ Scribble ” Code for , But when you know your code will be review The engineer submitted comment Call back , Naturally, it will be more careful : -)

3、 Find the underlying bug.

This is done by most teams Code Review Purpose . As mentioned above ,Code Review It works well in this respect . In fact, I think most of the code bug It should be unit tested , A functional test , Performance testing and regression testing to guarantee . But because static analysis doesn't understand the business , There are also some bug It's not easy to replicate in the test , In both cases , Experienced engineers come to review Code is especially important .

The next thing I want to talk about is to do Code Review What is the root cause of .

After all Code Review Is to add a process in the coding process , And it needs a lot of communication ,review The two sides may even have disputes because of different programming concepts , Various reasons lead to good results Code Review Not easy . The reality is that , such as v2ex There's a post on : Start a discussion , Your company has code review Do you ? , More than 100 engineers have answered this question , It can be seen from their answers that , do Code Review There are very few companies . Even in front-line Internet companies , There's also a lot of team opposition to Code Review , Chen Hao wrote an article :《 from Code Review Talk about how to do technology 》 , It is mentioned that the implementation in Ali Code Review The resistance to it , The reason for the objection is that the construction period is tight 、 Demand changes fast . If you don't want to know why Code Review , It's very easy to compromise in the face of obstacles , Take your time Code Review It's going to get out of shape , In the end, it becomes a mere formality . conversely , When we run into obstacles ,review When the code doesn't go well, it solves the problem with a positive attitude .

in my opinion , While we're doing the coding work , We also need to share architecture design from time to time , Exchange their own code ,Code Review It's about sharing architecture design all the time , The best way to communicate code . This is what we need to do Code Review Root cause of . The frequency of code exchange is very important , Before you design well , With skeleton code , After writing a function, you should submit it in time review, So that other engineers can keep abreast of your ideas , Communicate with you to realize the details . And those who think that the code only works , Or people who think no one should direct their code is obviously different from you and me , They won't be readers of this article : 

So how can we do it well Code Review Well ? Two aspects : One is to reduce the burden ,Code Review Just do what it should do . The second is to improve Code Review The efficiency of .

Code Review What should be discussed is function realization 、 Architecture design 、 Code quality , The following two things should not be done .

1、 Check code style and programming specifications .

Except for the newcomers , Code submitted by other engineers should not pass review To ensure the style of the code . The code styles mentioned here include but are not limited to : Naming specification 、 Code indentation 、 Comments and documentation, etc . You can use IDE Or other tools to ensure the unity of programming specifications and code style . If you're working on a code specification for your team , Sure follow Google Java Style  perhaps  Facebook Coding Standards . Here I recommend a good look Facebook The specification of , because Google The code specification tells you what to do , and Facebook The specification explains why this is done , And when you need to balance .

2、 Check for routine bad smell And code bug .

《 restructure 》  and  《Clean Code》  Pair code bad smell They all have very detailed descriptions . Team engineers should be familiar with these two books , Avoid these bad smell, such as : Duplicate code 、 Long Method 、 Oversize class 、 Two too close classes etc. , You can use IDE And static code checking tools  checkstyle、 findbugs  and  pmd  To help you check out these problems . Again , Most of the code bug It shouldn't be in Code Review Stage to discover , You should use static tools 、 unit testing 、 Integration testing and performance testing to discover them .

Let's talk about how to improve Code Review The efficiency of .

版权声明
本文为[Mujiutian]所创,转载请带上原文链接,感谢
https://chowdera.com/2020/12/20201206103620231a.html