Code review (sometimes referred to as peer review) is a software quality assurance activity in which one or more people examine the source code of a computer program, either after implementation or during the development process. The persons performing the checking, excluding the author, are called "reviewers". At least one reviewer must not be the code's author.[1][2]
Code review differs from related software quality assurance techniques like static code analysis,self-checks, testing, and pair programming. Static analysis relies primarily on automated tools, self-checks involve only the author, testing requires code execution, and pair programming is performed continuously during development rather than as a separate step.[1]
Goal
Although direct discovery of quality problems is often the main goal,[3] code reviews are usually performed to reach a combination of goals:[4][5]
Improving code quality – Improve internal code quality and maintainability through better readability, uniformity, and understandability
Detecting defects – Improve quality regarding external aspects, especially correctness, but also find issues such as performance problems, security vulnerabilities, and injected malware
Learning/Knowledge transfer – Sharing codebase knowledge, solution approaches, and quality expectations, both to the reviewers and the author
Increase sense of mutual responsibility – Increase a sense of collective code ownership and solidarity
Finding better solutions – Generate ideas for new and better solutions and ideas beyond the specific code at hand
Complying to QA guidelines, ISO/IEC standards – Code reviews are mandatory in some contexts, such as air traffic software and safety-critical software
Review types
Several variations of code review processes exist, with additional types specified in IEEE 1028.[6]
Management reviews
Technical reviews
Inspections
Walk-throughs
Audits
Inspection (formal)
Historically, the first code review process that was studied and described in detail was called "Inspection" by its inventor, Michael Fagan.[7]Fagan inspection is a formal process that involves a careful and detailed execution with multiple participants and phases. In formal code reviews, software developers attend a series of meetings to examine code line by line, often using printed copies. Research has shown formal inspections to be extremely thorough and highly effective at identifying defects.[7]
Regular change-based code review (Walk-throughs)
In recent years,[when?] many industry teams have adopted a lighter-weight review process in which the scope of each review is on the changes to the codebase performed in a ticket, user story, commit, or some other unit of work.[8][3] Furthermore, there are rules or conventions that integrate the review task into the development workflow through conventions like mandatory review of all tickets, commonly as part of a pull request, instead of explicitly planning each review. Such a process is called "regular, change-based code review".[1] There are many variations of this basic process. A 2017 survey of 240 development teams found that 90% of teams using code review followed a change-based process, with 60% specifically using regular change-based review.[3] Major software corporations including such as Microsoft,[9] Google,[10] and Facebook follow a change-based code review process.
Efficiency and effectiveness
Ongoing research by Capers Jones analyzing over 12,000 software development projects found formal inspections had a latent defect discovery rate of 60-65%, while informal inspections detected fewer than 50% of defects. The latent defect discovery rate for most forms of testing is about 30%.[11][12] A code review case study published in the book Best Kept Secrets of Peer Code Review contradicted the Capers Jones study,[11] finding that lightweight reviews can uncover as many bugs as formal reviews while being more efficient in terms of cost and money[13]
Studies indicate that up to 75% of code review comments affect software evolvability and maintainability rather than functionality,[14][15][4][16] suggesting that code reviews are an excellent tool for software companies with long product or system life cycles.[17] Therefore, less than 15% of issues discussed in code reviews relate directly to bugs.[18]
Guidelines
Research indicates review effectiveness correlates with review speed. Optimal code review rates range from 200 to 400 lines of code per hour.[19][20][21][22] Inspecting and reviewing more than a few hundred lines of code per hour for critical software (such as safety critical embedded software) may be too fast to find errors.[19][23]
Supporting tools
Static code analysis software assist reviewers by automatically checking source code for known vulnerabilities and defect patterns, particularly for large chunks of code.[24] A 2012 study by VDC Research reports that 17.6% of the embedded software engineers surveyed currently use automated tools to support peer code review and 23.7% planning to use them within two years.[25]
^ abcBaum, Tobias; Leßmann, Hendrik; Schneider, Kurt (2017). "The Choice of Code Review Process: A Survey on the State of the Practice". Product-Focused Software Process Improvement. Lecture Notes in Computer Science. Vol. 10611. pp. 111–127. doi:10.1007/978-3-319-69926-4_9. ISBN978-3-319-69925-7.
^Baum, Tobias; Liskin, Olga; Niklas, Kai; Schneider, Kurt (2016). "Factors Influencing Code Review Processes in Industry". Proceedings of the 2016 24th ACM SIGSOFT International Symposium on Foundations of Software Engineering - FSE 2016. pp. 85–96. doi:10.1145/2950290.2950323. ISBN9781450342186. S2CID15467294.
^ abFagan, Michael (1976). "Design and code inspections to reduce errors in program development". IBM Systems Journal. 15 (3): 182–211. doi:10.1147/sj.153.0182.
^Sadowski, Caitlin; Söderberg, Emma; Church, Luke; Sipko, Michal; Baachelli, Alberto (2018). "Modern code review: A case study at google". Proceedings of the 40th International Conference on Software Engineering: Software Engineering in Practice. pp. 181–190. doi:10.1145/3183519.3183525. ISBN9781450356596. S2CID49217999.
^ abKemerer, C.F.; Paulk, M.C. (2009-04-17). "The Impact of Design and Code Reviews on Software Quality: An Empirical Study Based on PSP Data". IEEE Transactions on Software Engineering. 35 (4): 534–550. doi:10.1109/TSE.2009.27. hdl:11059/14085. S2CID14432409.
^Balachandran, Vipin (2013). "Reducing human effort and improving quality in peer code reviews using automatic static analysis and reviewer recommendation". 2013 35th International Conference on Software Engineering (ICSE). pp. 931–940. doi:10.1109/ICSE.2013.6606642. ISBN978-1-4673-3076-3. S2CID15823436.