Code Review
-
Upload
rantav -
Category
Technology
-
view
4.026 -
download
0
description
Transcript of Code Review
![Page 1: Code Review](https://reader036.fdocuments.us/reader036/viewer/2022081420/5538d45955034680358b4878/html5/thumbnails/1.jpg)
Code Review
Tools and Process
@rantav
![Page 2: Code Review](https://reader036.fdocuments.us/reader036/viewer/2022081420/5538d45955034680358b4878/html5/thumbnails/2.jpg)
Formal Code Review Meetings
• A sit down meeting • Everyone looks at the code• Need to get prepared in advance• People bring up issues that need
to be fixed before you can go ahead with commit
![Page 3: Code Review](https://reader036.fdocuments.us/reader036/viewer/2022081420/5538d45955034680358b4878/html5/thumbnails/3.jpg)
Formal Code Review - The Pain
• Needs preparation• Time consuming• Hard to concentrate• No time to dig in and be
thorough• Difficult to schedule the right
ppl, especially at decentralized companies or projects
• Synergy - Yes• Cost effective - No• Fun - well...
![Page 4: Code Review](https://reader036.fdocuments.us/reader036/viewer/2022081420/5538d45955034680358b4878/html5/thumbnails/4.jpg)
Code Review in Apache
1.Every change has a jira issue2.A patch is uploaded3.A committer reviews and writes comments per the
patch4.When LGTM, the committer commits
![Page 5: Code Review](https://reader036.fdocuments.us/reader036/viewer/2022081420/5538d45955034680358b4878/html5/thumbnails/5.jpg)
Email Code Review
![Page 6: Code Review](https://reader036.fdocuments.us/reader036/viewer/2022081420/5538d45955034680358b4878/html5/thumbnails/6.jpg)
Offline Code Review Tools
• Jupiter - Eclipse prehistorical plugin• Mondrian - Google• Rietveld - Free and very limited Mondrian• ReviewBoard - The leading open source• Crubicle - from Atlassian ($$)• Code Collaborator - the leading $$ from SmartBear• Gerrit - git goodness
![Page 7: Code Review](https://reader036.fdocuments.us/reader036/viewer/2022081420/5538d45955034680358b4878/html5/thumbnails/7.jpg)
Mondrian
![Page 8: Code Review](https://reader036.fdocuments.us/reader036/viewer/2022081420/5538d45955034680358b4878/html5/thumbnails/8.jpg)
Rietveld
http://code.google.com/p/rietveld/
![Page 9: Code Review](https://reader036.fdocuments.us/reader036/viewer/2022081420/5538d45955034680358b4878/html5/thumbnails/9.jpg)
Code Collaborator
http://smartbear.com/codecollab.php
![Page 10: Code Review](https://reader036.fdocuments.us/reader036/viewer/2022081420/5538d45955034680358b4878/html5/thumbnails/10.jpg)
reviewboard
http://www.reviewboard.org/
![Page 11: Code Review](https://reader036.fdocuments.us/reader036/viewer/2022081420/5538d45955034680358b4878/html5/thumbnails/11.jpg)
Gerrithttp://code.google.com/p/gerrit/
![Page 12: Code Review](https://reader036.fdocuments.us/reader036/viewer/2022081420/5538d45955034680358b4878/html5/thumbnails/12.jpg)
Motivation
• Teach• Learn• Maintain coding conventions • Find defects early• Get more ppl familiar with the code (no job security)
![Page 13: Code Review](https://reader036.fdocuments.us/reader036/viewer/2022081420/5538d45955034680358b4878/html5/thumbnails/13.jpg)
Motivation - by the numbers
Average defect detection rate:25% for unit testing35% for functional testing45% for integration testing
Design and code reviews 55% at design review60% at code review
![Page 14: Code Review](https://reader036.fdocuments.us/reader036/viewer/2022081420/5538d45955034680358b4878/html5/thumbnails/14.jpg)
Motivation - by the numbers
Average defect detection rate:25% for unit testing35% for functional testing45% for integration testing
Design and code reviews 55% at design review60% at code review
![Page 15: Code Review](https://reader036.fdocuments.us/reader036/viewer/2022081420/5538d45955034680358b4878/html5/thumbnails/15.jpg)
When?
• Before commit?
• After commit?
• During commit (?)
![Page 16: Code Review](https://reader036.fdocuments.us/reader036/viewer/2022081420/5538d45955034680358b4878/html5/thumbnails/16.jpg)
Who?
• Manager• Tech lead• Architect• Peers
o Any peer from the teamo The one most likely to have
valuable input
![Page 17: Code Review](https://reader036.fdocuments.us/reader036/viewer/2022081420/5538d45955034680358b4878/html5/thumbnails/17.jpg)
Checklist (?)
• Does the code build correctly?• Does the code execute as expected?• Is all new code tested? Altered code tests up to date?• Is the code readable?• Do you understand the code you are reviewing?• Has the developer tested the code?• coding conventions?• Are all functions, methods and classes documented?• Are complex algorithms and code optimizations adequately commented?• Error Handling• Resource Leaks• Thread Safeness• Is the code free of unintended infinite loops?• Are function parameters explicitly verified in the code?• Pending/TODO• assertions• abnormal terminations• Database Transactions• Correct synchronization• no deadlocks/livelocks• Bug Fix Side Effects• All the occurrences of the bug are fixed
![Page 18: Code Review](https://reader036.fdocuments.us/reader036/viewer/2022081420/5538d45955034680358b4878/html5/thumbnails/18.jpg)
Different Techniques - recap
• email• jira patch process a la apache• over the shoulder• formal review at a meeting room• pasetbin• web tools - reviewboard and such• GitHub - fork-review-pull process
![Page 19: Code Review](https://reader036.fdocuments.us/reader036/viewer/2022081420/5538d45955034680358b4878/html5/thumbnails/19.jpg)
Tips for Effective Code Review
• Psychology - Let's face it, there's a lot of psychology in it, so play nice.
• Be professional, nothing is personal• Strive to understand, not criticize.• Get prepared
o understand the technology in useo know the coding conventionso read related code (classes/method
being used)• Read Slow• Short
![Page 20: Code Review](https://reader036.fdocuments.us/reader036/viewer/2022081420/5538d45955034680358b4878/html5/thumbnails/20.jpg)
What's Short?
• No more than 60 minutes• No more than 200 LOC (C code)
![Page 21: Code Review](https://reader036.fdocuments.us/reader036/viewer/2022081420/5538d45955034680358b4878/html5/thumbnails/21.jpg)
Challenges ( לא (למה
• Ego
• The Hassle
![Page 22: Code Review](https://reader036.fdocuments.us/reader036/viewer/2022081420/5538d45955034680358b4878/html5/thumbnails/22.jpg)
The Book
![Page 23: Code Review](https://reader036.fdocuments.us/reader036/viewer/2022081420/5538d45955034680358b4878/html5/thumbnails/23.jpg)
Related
• Pair Programming• Code Reading (Doug Crockford)• Static Analysis tools
![Page 24: Code Review](https://reader036.fdocuments.us/reader036/viewer/2022081420/5538d45955034680358b4878/html5/thumbnails/24.jpg)
Extra slides
![Page 25: Code Review](https://reader036.fdocuments.us/reader036/viewer/2022081420/5538d45955034680358b4878/html5/thumbnails/25.jpg)
Eye tracking01 void main(void){ 02 int i, num, isPrime = 0; 03 04 printf("Input Number:"); 05 scanf("%d", &num); 06 07 i = 2; 08 while(i < num){ 09 if(num%i == 0) 10 isPrime = 1; 11 i = i + 1; 12 } 13 14 if(isPrime == 1) 15 printf("%d is prime number.¥n", num); 16 else 17 printf("%d is NOT prime number.¥n", num); 18 }
![Page 26: Code Review](https://reader036.fdocuments.us/reader036/viewer/2022081420/5538d45955034680358b4878/html5/thumbnails/26.jpg)
Eye tracking (2)
![Page 27: Code Review](https://reader036.fdocuments.us/reader036/viewer/2022081420/5538d45955034680358b4878/html5/thumbnails/27.jpg)
Eye tracking (3)
=> Now there's a physiological reason to write short method.
=> People who spend more time on the first scan find more issues and find them faster
![Page 28: Code Review](https://reader036.fdocuments.us/reader036/viewer/2022081420/5538d45955034680358b4878/html5/thumbnails/28.jpg)
Defect density vs LOC
http://smartbear.com/white-paper.php?content=docs/articles/Case-Study.html
Conclusion: Don't review too much code at once (<200-400 LOC)
![Page 29: Code Review](https://reader036.fdocuments.us/reader036/viewer/2022081420/5538d45955034680358b4878/html5/thumbnails/29.jpg)
Defect density vs LOC/hour
Conclusion: Take your time (<500 LOC/hour)http://smartbear.com/white-paper.php?content=docs/articles/Case-Study.html
![Page 30: Code Review](https://reader036.fdocuments.us/reader036/viewer/2022081420/5538d45955034680358b4878/html5/thumbnails/30.jpg)
Author preperation
Conclusion: Author preparation results in more efficient reviewshttp://smartbear.com/white-paper.php?content=docs/articles/Case-Study.html