Tuesday, September 3, 2019

Code Review Process: Best Practices


Software development includes multiple phases such as planning, design, development, code review, testing, maintenance. Each phase has its own significance to acquire a goal. If there are some issues within a single stage, the software will fail. Among these code review is an important process.

What is code review?

Code review is a phase in software quality assurance activity in which code authors, peer reviewers, and quality assurance testers check a program by viewing and reading parts of the source code. Finding and correcting errors at this stage is not expensive, and it reduces the cost of handling, locating and fixing bugs on later stages or after delivery of programs. In this process at least one of the persons must not be a code’s author. Reviewers are the persons performing the checking, other than author.

Goals of Code review Process-

1. Better Code Quality-

This process improves the internal code quality and maintainability which includes readability, uniformity, understandability.

2. Find Defects-

It improves the correctness and quality, detect problems about performance, security, injected malware etc.

3. Knowledge Transfer-

It helps to transfer the knowledge about code and solution to reviewers and authors.

4. Finding Better Solutions-

It helps to generate ideas for new and better solutions.

5. Complying to QA guidelines-

Code reviews are important in some context such as air traffic software.
Automated code review simplify the systematic testing of source code for issues such as buffer overflows, race conditions, memory leakage, size violations and duplicate statements. Code review is mainly carried out to test the quality of part of source code. 

Best Practices of Code Review Process-

1. Review code of 200-400 lines one at a time-

Defect density VS LOC
If you try to review too many lines of code at once, you couldn’t find defects. From analysis it has been found that the human brain can able to detect defects effectively within 400 lines of code at once. After this limit the tendency of the brain to detect defects diminishes. A review of 200-400 LOC over 60-90 minutes can detect 70-90% of defects. For eg., if the code has 10 defects, within this limit the human brain can detect around 7-9 defects of them.

2. Take your time. Inspection rate should below 500 LOC per hour-

Defect Density VS Inspection Rate
Sometimes it can be possible that someone could catch the error that you don’t. Research shows that there will be effective drop in finding defect density at a rate faster than 500 LOC per hour. Code review in reasonable quantity at slower speed in limited speed results in most effective code review. 

3. Do not review more than 60 minutes at once-

Performance will go down in usual code review process after 60 minutes. So you should not review code at fast rate, also you should not review for too long in one sitting. Studies show that taking a break within a task over a period of time improves the work quality. So it is best to do a review in short sessions. Taking a break will refresh your brain and get ready to detect defects with a fresh eye.

4. Set Goals and capture metrics-

Before starting to a process, a team should decide how they will measure the effectiveness of process work and set goals to complete the process. Start with external metrics such as reduce support calls, reduce the defects in developments. This information will give you a numeric report that is understandable and can be improved to achieve an effective goal. A metrics driven code review tool collects data automatically so that your data is accurate.

5. Authors should annotate source code-

Before the review is initiated, authors should annotate the code which will show about which files to look and review first to do every source code modification. Annotations helps reviewers to ease the process and provide more deep knowledge in context. It also helps to find errors before starting of review. It helps to find bugs more easily and results in higher quality. Author has to re-think and explain the changes during the annotation process, the author will uncover many of the defects before the review even begins, thus making the review itself more efficient.

6. Use Checklist-

Code review Checklist
It is common to many times that authors do the same mistakes again and again. And it is difficult to find that is not there. In such cases checklists are the most effective way to avoid the frequent made errors. Code review checklist is gives team members a clear goal for each type of review and it can be helpful to track reporting and improves the process. Using checklist reviewer can enlist the defects that hasn’t been solved. 

7. Foster A good code review-

Code review is the important stage. It not only creates a good team but also means for learning,growing and communication if manager promote it. Detecting defects is easy but the negative impact towards defects found can depreciate the whole team. The main target of code review process is to eliminate as many defects as possible,  instead of who created the error. Managers must promote the view that defects are positive. Code review is the process to make your code as well as possible. Every defect found and fixed in review is a defect that customer couldn’t see and also QA doesn’t have to spend time to track it.

8. Use lightweight code reviews-

To completely utilize your team’s time and to effectively measure the results a lightweight process is recommended. If the tool is not convenient to use by a team,the result will not be effective. Lightweight code reviews takes 20% less time than formal reviews and able to find more bugs as formal review process.

9. Give Feedback-

Giving feedback to a person could be the proper way to communicate in a positive manner. Try to be positive or effective instead of critical in feedback. You should ask questions instead of giving statements. Code review comments are the mediator between communication of programmer and user.

10. Verify that defects are actually fixed-

Many times reviewer don’t have a good way to track the defects during the review process and also ensuring that bugs are fixed before the completion of the review. Then what is a good way to ensure that defects are fixed.You can use collaborative review software, which is integrated with rational team concert to track defects found in reviews. By using the proper tool reviewers can track bugs and discuss with author. Resolving of issue is notified by the reviewer when author fixes the problem. After resolving all the bugs, work would be approved.
Are you thinking for a web solution for your business? Solace is a software development company which specializes in effective custom development using code review processes. Developers at solace are well known about code review practices for effective development. For any web development, Contact us. We are happy to help you get started through our expert’s.

No comments:

Post a Comment