How to improve the quality of the code (Management chapter): Code review
Perhaps you are a project manager, perhaps you are a core member of the project or development team leader. I published "How to improve code quality" of the system after the article, many users have complained to me that he could not grasp the entire project team's code quality. I think this is common problem for all project team it, it manifests itself in the following questions:
Common problem of software project
1) novice. Any project team members are inevitably novice, they are often just graduated from college students. These novice as software development time is too short, often immature technology, the development does not form a good habit of writing code so the poor quality of many problems. They often become the team's "weak", with more project quality can not be guaranteed, then they do not have enough people.
2) personnel changes. A little bit longer maintenance time software projects, staff changes are inevitable. Older employees were transferred to other projects go, the new staff to take over their work. In my project group, the mobility was 90%, the only thing I transferred. The new staff take over the old code maintenance staff, and even proceed with new development, because the original code and design ideas to understand the bias, there will be a lot of bad code.
3) non-standard coding. Even excluding the impact of these two issues, the project team members write code that will have problems. In the beginning of project development, we tend to develop a coding specification, but in the project development process, many members tend to ignore these norms to arbitrary code written. Arbitrarily coding will reduce readability, maintainability and ease of change of. So what we should use management measures to ensure that the code specification, improve code quality?
These problems, which I constantly explored in the project development and think about, and some experienced project managers presented their solution, that is, "code review."
What is a code review
Code review (Code Review), also known as "code review" the basic idea is that developers write their code completed by other people to review his code, so as to effectively find defects in code. Code review of a basic theory is that the sooner we find defects in code, we solve the lower the cost of defects. Code review is often divided into the following one aspect of the review:
1) code style. In the beginning of project development, we tend to develop a coding specification, in fact, the code specification to include the entire project team's code style. As software developers design traditions, if not unified code style, a project code will be varied, such as the naming of variables and constants, interface and implementation class notes, when the carriage returns, indents, etc. how. A wide variety of design styles, will maintain and improve for the future difficult. Through the code review, on the one hand to urge developers to write code according to specification, it also enables developers to program their own form good habits. Code style review, since the content is relatively simple, we often through some code review tools to automate and improve the efficiency review.
2) The major defect. In some articles on the Code Review in a list of the list often to describe the code review should focus on Zhu Yi's Major defects , including: there is SQL injection, vulnerable to cross-site scripting, buffer overflow Ou, managed code, etc. . Project team can accumulate a significant defect review the project, and one by one check in each review. Major defect is a tedious and meticulous review of the work, if they can write or use some review of the software, can greatly improve the efficiency of our review.
3) review of the design logic and thinking. I think that part of the review of the code review is the most crucial and most valuable part. Code style review with major defects, although important, but simple and mechanical, can automatically check software; and design review of the logic and ideas, but it is complex and in-depth review of the need to have some theoretical depth and experience of the person to complete coding , and the novice is particularly important. Mentioned earlier, the novice is the inevitable question of any project team. Unfortunately, many project managers of the solution is simple and only a small amount of work to complete novices, but a large number of complex work to the small number of those veterans to complete. The result is that novices are always new to them without adequate training; veteran exhausted Lei Huo, can not be expected to share the work of novices. For this problem, my approach is through code review, to guide the novice to veteran, so as to enhance the overall quality of the team. Specific way, in the novice after the completion of coding, so veterans to conduct code review, pointed out that the novice's question, guide novice design. This process may need to reconstruct the original, or even re-encoding. However, after this process, the novice will gradually skilled, fast becoming a veteran, and the overall improvement in the quality team.
Advantages and disadvantages in the form of code review
After the above description, we can find the code review are clear advantages.
First of all, through the style and standard of review of the code, you can greatly improve code readability and maintainability. Now the software, often require ongoing maintenance and upgrades, staff changes are inevitable, so the code readability and maintainability is particularly important. Code review is an encouragement, because it is there, urging the developers to consciously regulate code, to develop good coding habits, improve code quality. An interesting question is, if you do not read other people's code, never understanding what the code is readable, and not let other people read their own code and feedback, and will never know that their code is readable, Even if you're a coding veteran of many years. Code review is precisely to solve this problem, which you can try.
Second, the code review is an exchange between programmers. Novice can have more opportunities and guidance to veterans to learn and improve their design level (it should be said that this is very valuable for them); veterans through the guidance of the novice, organize and sublimate their design ideas and theories, but also for the other hand, exercise and improve their own. In addition, when you find someone else pointed out a problem later, but also in the warning myself not to make the same mistakes, which were reviewed and the reviewers were helpful.
Although the code review to have such outstanding merit, but its drawback is also very significant that it needs to pay such a heavy price. When a person after the completion of coding, but also other people to interpret and review and required programmers to perform the corresponding modification, or reconstruction and rewriting, which itself is a heavy price. This in itself has been very tight and time of software development projects, is undoubtedly a worse. Time, manpower and code quality, which itself can not have both fish and bear's paw, the key is how to balance. Because of this, different companies chose a different strategy for the code review.
Not long ago, I heard a big game software company, South Korea on their code review. As the company in software development, time and manpower is not the most critical and critical code quality problems, so they adopted a strict code review strategy. Strict code review strategy, a way to code by hand for review. In this way, the staff of organizational form, separate from the software developer made a number of experienced people to form a code review team, allied to other software development team code review. In this way, the code review team to a third party to review the status code for each project team can ensure fair and impartial review, but the pressure will be enormous (think they want to see so much code).
Another way, is a project development team for the unit code-checking each other, that one's code, to all members of the Panel for review. There is no doubt in this way, its costs too. A variation on this approach is to XP in the way of pair programming to integrate, contingently, the two people on the programming code for each check each other. Pair programming with the project team can try in this way, unfortunately, is currently the use of pair programming, project team were too few. Above the maximum of two evils is the code review responsibility, that is the responsibility of the reviewers do not have much to be discovered by examination of those issues, the review found that the problem has nothing to do good, sculptors and were reviewed by grudges; the contrary, those who did not review found that the problem will not bear any responsibility. This result has led to code review a mere formality: a review of those cursory review of the parties happy, the problem still exists.
In summary, although the code review obvious advantages, but some forms can not be more than an ordinary software development team accepted this, I resorted to my best practice: as a group, head of the responsibility of the code review form.
Code review best practices
Code review is a cost, sometimes enormous, so the code review should not be frequent, the best review of a code only once. Meanwhile, the code review shall review the code on the responsibility, that is, to boldly review also said that the review of those issues and asked to be reviewers deadline for correction. At the same time, after review of the code is there if it is defective, the review shall responsible. Only meet the three conditions above, the code review can be acceptable for us. There is no doubt that the project development team leader to assume this responsibility is the most appropriate.
A project development group, classified according to their function, can be divided into several groups, each responsible for a sub-module. In such a group, the team leader is undoubtedly the most experienced developer, charged with this matter is responsible for organizing and guiding other members is appropriate. Members of the group not too much, often 3 to 5. Team leader not to allocate too many development tasks, his main job is to guide and supervise other members of the development team. The development of his mandate from the heavy freed, he can have more energy to guide the other members of the design and review their code. Ultimately, he wants to all members of the group responsible for the quality of code, the project manager or quality manager for sampling and checking of the overall situation.
If you are just a small project, staff within a total of 5 people, then you do not have such a group. As project manager you're the team leader, guidance and supervision of your members. This arrangement is because in modern management theory that a person can only manage five individuals, more than five individuals should be grouped management. 5 If you do not need to separate within the course Rights.
As a leader, you can effectively review and manage your team. Also, because you responsible, you have to seriously and effectively to complete the review. The above forms of organization, code review can easily and effectively carried out in the project team together, thereby effectively improving the management of software development, code quality.
Reprinted from: http://www.javaeye.com/topic/599976