Peer Code Review - SE4Science · 2020. 6. 2. · Simplified Gerrit workflow 26 No Developer’s...
Transcript of Peer Code Review - SE4Science · 2020. 6. 2. · Simplified Gerrit workflow 26 No Developer’s...
![Page 1: Peer Code Review - SE4Science · 2020. 6. 2. · Simplified Gerrit workflow 26 No Developer’s Local Branch Main project branch Reviewer Approved Developer Yes Pull to local branch](https://reader034.fdocuments.in/reader034/viewer/2022051918/600a1de45d2b3755d302736a/html5/thumbnails/1.jpg)
Contemporary Peer Code Review Practices
Jeffrey C. CarverNasir U. Eisty
University of Alabama
![Page 2: Peer Code Review - SE4Science · 2020. 6. 2. · Simplified Gerrit workflow 26 No Developer’s Local Branch Main project branch Reviewer Approved Developer Yes Pull to local branch](https://reader034.fdocuments.in/reader034/viewer/2022051918/600a1de45d2b3755d302736a/html5/thumbnails/2.jpg)
2
Can you spot the mistakes?
![Page 3: Peer Code Review - SE4Science · 2020. 6. 2. · Simplified Gerrit workflow 26 No Developer’s Local Branch Main project branch Reviewer Approved Developer Yes Pull to local branch](https://reader034.fdocuments.in/reader034/viewer/2022051918/600a1de45d2b3755d302736a/html5/thumbnails/3.jpg)
// file: IVR.CPPvoid IVR(){
//press 1 for account balance, 2 for last transaction,//3 for last statement, any other for operatorplay_prompt();
int key_pressed= get_user_choice();if(key_pressed ==1){
play_account_balance();}else if(key_pressed =2){
play_last_transaction();}else if(key_pressed ==3){
play_last_statement();}else transfer_to_operator();
}
3
Assignment operatorinstead of comparison
12345678910111213141516171819202122
![Page 4: Peer Code Review - SE4Science · 2020. 6. 2. · Simplified Gerrit workflow 26 No Developer’s Local Branch Main project branch Reviewer Approved Developer Yes Pull to local branch](https://reader034.fdocuments.in/reader034/viewer/2022051918/600a1de45d2b3755d302736a/html5/thumbnails/4.jpg)
//file: printer.javaif (user.isAuthenticated){
userAccess = checkUserAuthorization(user);
//if user has access to printer if(user.isAuthenticated && userAccess.printer)
printUsageReport ();else
emailUsageReport();}
4
1234567891011
Redundant check
![Page 5: Peer Code Review - SE4Science · 2020. 6. 2. · Simplified Gerrit workflow 26 No Developer’s Local Branch Main project branch Reviewer Approved Developer Yes Pull to local branch](https://reader034.fdocuments.in/reader034/viewer/2022051918/600a1de45d2b3755d302736a/html5/thumbnails/5.jpg)
//file: UserStats.java
String[] listOfUsers = getUsersList();
//print all the users name
for(int i=1;i< listOfUsers.length();i++)
System.out.println(“User# “+i +”: “+listOfUsers[i]);
5
123456
Will not print first user
![Page 6: Peer Code Review - SE4Science · 2020. 6. 2. · Simplified Gerrit workflow 26 No Developer’s Local Branch Main project branch Reviewer Approved Developer Yes Pull to local branch](https://reader034.fdocuments.in/reader034/viewer/2022051918/600a1de45d2b3755d302736a/html5/thumbnails/6.jpg)
Do you think only novice developers make those
mistakes?
![Page 7: Peer Code Review - SE4Science · 2020. 6. 2. · Simplified Gerrit workflow 26 No Developer’s Local Branch Main project branch Reviewer Approved Developer Yes Pull to local branch](https://reader034.fdocuments.in/reader034/viewer/2022051918/600a1de45d2b3755d302736a/html5/thumbnails/7.jpg)
7
![Page 8: Peer Code Review - SE4Science · 2020. 6. 2. · Simplified Gerrit workflow 26 No Developer’s Local Branch Main project branch Reviewer Approved Developer Yes Pull to local branch](https://reader034.fdocuments.in/reader034/viewer/2022051918/600a1de45d2b3755d302736a/html5/thumbnails/8.jpg)
8
![Page 9: Peer Code Review - SE4Science · 2020. 6. 2. · Simplified Gerrit workflow 26 No Developer’s Local Branch Main project branch Reviewer Approved Developer Yes Pull to local branch](https://reader034.fdocuments.in/reader034/viewer/2022051918/600a1de45d2b3755d302736a/html5/thumbnails/9.jpg)
9
![Page 10: Peer Code Review - SE4Science · 2020. 6. 2. · Simplified Gerrit workflow 26 No Developer’s Local Branch Main project branch Reviewer Approved Developer Yes Pull to local branch](https://reader034.fdocuments.in/reader034/viewer/2022051918/600a1de45d2b3755d302736a/html5/thumbnails/10.jpg)
10
![Page 11: Peer Code Review - SE4Science · 2020. 6. 2. · Simplified Gerrit workflow 26 No Developer’s Local Branch Main project branch Reviewer Approved Developer Yes Pull to local branch](https://reader034.fdocuments.in/reader034/viewer/2022051918/600a1de45d2b3755d302736a/html5/thumbnails/11.jpg)
To Err is Human
![Page 12: Peer Code Review - SE4Science · 2020. 6. 2. · Simplified Gerrit workflow 26 No Developer’s Local Branch Main project branch Reviewer Approved Developer Yes Pull to local branch](https://reader034.fdocuments.in/reader034/viewer/2022051918/600a1de45d2b3755d302736a/html5/thumbnails/12.jpg)
12
![Page 13: Peer Code Review - SE4Science · 2020. 6. 2. · Simplified Gerrit workflow 26 No Developer’s Local Branch Main project branch Reviewer Approved Developer Yes Pull to local branch](https://reader034.fdocuments.in/reader034/viewer/2022051918/600a1de45d2b3755d302736a/html5/thumbnails/13.jpg)
Typical Code Review Workflow
13
![Page 14: Peer Code Review - SE4Science · 2020. 6. 2. · Simplified Gerrit workflow 26 No Developer’s Local Branch Main project branch Reviewer Approved Developer Yes Pull to local branch](https://reader034.fdocuments.in/reader034/viewer/2022051918/600a1de45d2b3755d302736a/html5/thumbnails/14.jpg)
14
Writes Reviews
RequestsReview
Edits
Abandon
Merge
![Page 15: Peer Code Review - SE4Science · 2020. 6. 2. · Simplified Gerrit workflow 26 No Developer’s Local Branch Main project branch Reviewer Approved Developer Yes Pull to local branch](https://reader034.fdocuments.in/reader034/viewer/2022051918/600a1de45d2b3755d302736a/html5/thumbnails/15.jpg)
Mailing List Code Review
15
![Page 16: Peer Code Review - SE4Science · 2020. 6. 2. · Simplified Gerrit workflow 26 No Developer’s Local Branch Main project branch Reviewer Approved Developer Yes Pull to local branch](https://reader034.fdocuments.in/reader034/viewer/2022051918/600a1de45d2b3755d302736a/html5/thumbnails/16.jpg)
16
![Page 17: Peer Code Review - SE4Science · 2020. 6. 2. · Simplified Gerrit workflow 26 No Developer’s Local Branch Main project branch Reviewer Approved Developer Yes Pull to local branch](https://reader034.fdocuments.in/reader034/viewer/2022051918/600a1de45d2b3755d302736a/html5/thumbnails/17.jpg)
Contemporary Code Reviews
17
![Page 18: Peer Code Review - SE4Science · 2020. 6. 2. · Simplified Gerrit workflow 26 No Developer’s Local Branch Main project branch Reviewer Approved Developer Yes Pull to local branch](https://reader034.fdocuments.in/reader034/viewer/2022051918/600a1de45d2b3755d302736a/html5/thumbnails/18.jpg)
18
![Page 19: Peer Code Review - SE4Science · 2020. 6. 2. · Simplified Gerrit workflow 26 No Developer’s Local Branch Main project branch Reviewer Approved Developer Yes Pull to local branch](https://reader034.fdocuments.in/reader034/viewer/2022051918/600a1de45d2b3755d302736a/html5/thumbnails/19.jpg)
19
IssuesIdentified in code review
![Page 20: Peer Code Review - SE4Science · 2020. 6. 2. · Simplified Gerrit workflow 26 No Developer’s Local Branch Main project branch Reviewer Approved Developer Yes Pull to local branch](https://reader034.fdocuments.in/reader034/viewer/2022051918/600a1de45d2b3755d302736a/html5/thumbnails/20.jpg)
20
![Page 21: Peer Code Review - SE4Science · 2020. 6. 2. · Simplified Gerrit workflow 26 No Developer’s Local Branch Main project branch Reviewer Approved Developer Yes Pull to local branch](https://reader034.fdocuments.in/reader034/viewer/2022051918/600a1de45d2b3755d302736a/html5/thumbnails/21.jpg)
Scientific Code Review
21
![Page 22: Peer Code Review - SE4Science · 2020. 6. 2. · Simplified Gerrit workflow 26 No Developer’s Local Branch Main project branch Reviewer Approved Developer Yes Pull to local branch](https://reader034.fdocuments.in/reader034/viewer/2022051918/600a1de45d2b3755d302736a/html5/thumbnails/22.jpg)
22
![Page 23: Peer Code Review - SE4Science · 2020. 6. 2. · Simplified Gerrit workflow 26 No Developer’s Local Branch Main project branch Reviewer Approved Developer Yes Pull to local branch](https://reader034.fdocuments.in/reader034/viewer/2022051918/600a1de45d2b3755d302736a/html5/thumbnails/23.jpg)
23
![Page 24: Peer Code Review - SE4Science · 2020. 6. 2. · Simplified Gerrit workflow 26 No Developer’s Local Branch Main project branch Reviewer Approved Developer Yes Pull to local branch](https://reader034.fdocuments.in/reader034/viewer/2022051918/600a1de45d2b3755d302736a/html5/thumbnails/24.jpg)
24
![Page 25: Peer Code Review - SE4Science · 2020. 6. 2. · Simplified Gerrit workflow 26 No Developer’s Local Branch Main project branch Reviewer Approved Developer Yes Pull to local branch](https://reader034.fdocuments.in/reader034/viewer/2022051918/600a1de45d2b3755d302736a/html5/thumbnails/25.jpg)
25
![Page 26: Peer Code Review - SE4Science · 2020. 6. 2. · Simplified Gerrit workflow 26 No Developer’s Local Branch Main project branch Reviewer Approved Developer Yes Pull to local branch](https://reader034.fdocuments.in/reader034/viewer/2022051918/600a1de45d2b3755d302736a/html5/thumbnails/26.jpg)
Simplified Gerrit workflow
26
No
Developer’s Local Branch
Main project branch
Reviewer
Approved
Developer
Yes
Push to mainPull to local branch
Push to Gerrit
Notifies developer
ReviewsCode
Notifies
![Page 27: Peer Code Review - SE4Science · 2020. 6. 2. · Simplified Gerrit workflow 26 No Developer’s Local Branch Main project branch Reviewer Approved Developer Yes Pull to local branch](https://reader034.fdocuments.in/reader034/viewer/2022051918/600a1de45d2b3755d302736a/html5/thumbnails/27.jpg)
Gerrit Repository Structure
27
![Page 28: Peer Code Review - SE4Science · 2020. 6. 2. · Simplified Gerrit workflow 26 No Developer’s Local Branch Main project branch Reviewer Approved Developer Yes Pull to local branch](https://reader034.fdocuments.in/reader034/viewer/2022051918/600a1de45d2b3755d302736a/html5/thumbnails/28.jpg)
Gerrit Terminology
• Change:• The unit of review• Every git commit has a change-id• Results in a single commit when merged to the Git
repository• Change numbers are unique and never change
• Patch Set:• A revision of a Change• Each time a Change is modified, it will receive a
new patch set• Patch set numbering starts from 1 • Technically, a patch set is a unique Git commit
28
![Page 29: Peer Code Review - SE4Science · 2020. 6. 2. · Simplified Gerrit workflow 26 No Developer’s Local Branch Main project branch Reviewer Approved Developer Yes Pull to local branch](https://reader034.fdocuments.in/reader034/viewer/2022051918/600a1de45d2b3755d302736a/html5/thumbnails/29.jpg)
Gerrit Terminology• Label
• A rating category that allows or blocks progress of a change. (i.e. Build, Deploy, Code Review)
• Score• The rating given to a label. • Code review spans +2 to -2
• Submit• Merges a change into the repository - until this happens, the
code is outside of the repo
• Abandon• Archives a change (can be restored later)
• Project• A Git repository
29
![Page 30: Peer Code Review - SE4Science · 2020. 6. 2. · Simplified Gerrit workflow 26 No Developer’s Local Branch Main project branch Reviewer Approved Developer Yes Pull to local branch](https://reader034.fdocuments.in/reader034/viewer/2022051918/600a1de45d2b3755d302736a/html5/thumbnails/30.jpg)
Review Scores
Score Description Action
-2 This shall not be merged Blocks submit
-1 I would prefer this is not merged as is None
0 No score None
+1 Looks good to me, but someone else must approve
None
+2 Looks good to me, approved Allows submit
30
![Page 31: Peer Code Review - SE4Science · 2020. 6. 2. · Simplified Gerrit workflow 26 No Developer’s Local Branch Main project branch Reviewer Approved Developer Yes Pull to local branch](https://reader034.fdocuments.in/reader034/viewer/2022051918/600a1de45d2b3755d302736a/html5/thumbnails/31.jpg)
Gerrit Installation
http://bit.ly/Gerrit-Tutorial-SEA18
31
![Page 32: Peer Code Review - SE4Science · 2020. 6. 2. · Simplified Gerrit workflow 26 No Developer’s Local Branch Main project branch Reviewer Approved Developer Yes Pull to local branch](https://reader034.fdocuments.in/reader034/viewer/2022051918/600a1de45d2b3755d302736a/html5/thumbnails/32.jpg)
Code Review Exercise 1
![Page 33: Peer Code Review - SE4Science · 2020. 6. 2. · Simplified Gerrit workflow 26 No Developer’s Local Branch Main project branch Reviewer Approved Developer Yes Pull to local branch](https://reader034.fdocuments.in/reader034/viewer/2022051918/600a1de45d2b3755d302736a/html5/thumbnails/33.jpg)
• Pair with a neighbor
• Download dayOfYear.java from: http://SE4Science.org/CodeReview-SEA/
• Upload code to the “exercise”repositoryyou created while setting up GerritHub
• Add your partner as a reviewer
• Review each other’s code
33
![Page 34: Peer Code Review - SE4Science · 2020. 6. 2. · Simplified Gerrit workflow 26 No Developer’s Local Branch Main project branch Reviewer Approved Developer Yes Pull to local branch](https://reader034.fdocuments.in/reader034/viewer/2022051918/600a1de45d2b3755d302736a/html5/thumbnails/34.jpg)
Discussion
![Page 35: Peer Code Review - SE4Science · 2020. 6. 2. · Simplified Gerrit workflow 26 No Developer’s Local Branch Main project branch Reviewer Approved Developer Yes Pull to local branch](https://reader034.fdocuments.in/reader034/viewer/2022051918/600a1de45d2b3755d302736a/html5/thumbnails/35.jpg)
35
Don’t repeat yourself
![Page 36: Peer Code Review - SE4Science · 2020. 6. 2. · Simplified Gerrit workflow 26 No Developer’s Local Branch Main project branch Reviewer Approved Developer Yes Pull to local branch](https://reader034.fdocuments.in/reader034/viewer/2022051918/600a1de45d2b3755d302736a/html5/thumbnails/36.jpg)
36
Comments Where Needed
![Page 37: Peer Code Review - SE4Science · 2020. 6. 2. · Simplified Gerrit workflow 26 No Developer’s Local Branch Main project branch Reviewer Approved Developer Yes Pull to local branch](https://reader034.fdocuments.in/reader034/viewer/2022051918/600a1de45d2b3755d302736a/html5/thumbnails/37.jpg)
37
Fail Fast
February 9, 2019
dayOfYear(1,9,2019) dayOfYear(9,2,2019)
dayOfYear(2019,2,9)
![Page 38: Peer Code Review - SE4Science · 2020. 6. 2. · Simplified Gerrit workflow 26 No Developer’s Local Branch Main project branch Reviewer Approved Developer Yes Pull to local branch](https://reader034.fdocuments.in/reader034/viewer/2022051918/600a1de45d2b3755d302736a/html5/thumbnails/38.jpg)
38
Fail Faster
dayOfYear(String month, int dayOfMonth, int year) { ...
}
![Page 39: Peer Code Review - SE4Science · 2020. 6. 2. · Simplified Gerrit workflow 26 No Developer’s Local Branch Main project branch Reviewer Approved Developer Yes Pull to local branch](https://reader034.fdocuments.in/reader034/viewer/2022051918/600a1de45d2b3755d302736a/html5/thumbnails/39.jpg)
39
Avoid Magic Numbers
![Page 40: Peer Code Review - SE4Science · 2020. 6. 2. · Simplified Gerrit workflow 26 No Developer’s Local Branch Main project branch Reviewer Approved Developer Yes Pull to local branch](https://reader034.fdocuments.in/reader034/viewer/2022051918/600a1de45d2b3755d302736a/html5/thumbnails/40.jpg)
40
One Purpose for each variable
![Page 41: Peer Code Review - SE4Science · 2020. 6. 2. · Simplified Gerrit workflow 26 No Developer’s Local Branch Main project branch Reviewer Approved Developer Yes Pull to local branch](https://reader034.fdocuments.in/reader034/viewer/2022051918/600a1de45d2b3755d302736a/html5/thumbnails/41.jpg)
Code Review Exercise 2
![Page 42: Peer Code Review - SE4Science · 2020. 6. 2. · Simplified Gerrit workflow 26 No Developer’s Local Branch Main project branch Reviewer Approved Developer Yes Pull to local branch](https://reader034.fdocuments.in/reader034/viewer/2022051918/600a1de45d2b3755d302736a/html5/thumbnails/42.jpg)
• Keep the same pair
• Download leapYear.java from: http://SE4Science.org/CodeReview-SEA/
• Upload the code to the “exercise”repository you created while setting up GerritHub
• Add your partner as a reviewer
• Review each other’s code 42
![Page 43: Peer Code Review - SE4Science · 2020. 6. 2. · Simplified Gerrit workflow 26 No Developer’s Local Branch Main project branch Reviewer Approved Developer Yes Pull to local branch](https://reader034.fdocuments.in/reader034/viewer/2022051918/600a1de45d2b3755d302736a/html5/thumbnails/43.jpg)
43
Use Good Names
secondsPerDay = 86400
![Page 44: Peer Code Review - SE4Science · 2020. 6. 2. · Simplified Gerrit workflow 26 No Developer’s Local Branch Main project branch Reviewer Approved Developer Yes Pull to local branch](https://reader034.fdocuments.in/reader034/viewer/2022051918/600a1de45d2b3755d302736a/html5/thumbnails/44.jpg)
44
Magic Numbers
![Page 45: Peer Code Review - SE4Science · 2020. 6. 2. · Simplified Gerrit workflow 26 No Developer’s Local Branch Main project branch Reviewer Approved Developer Yes Pull to local branch](https://reader034.fdocuments.in/reader034/viewer/2022051918/600a1de45d2b3755d302736a/html5/thumbnails/45.jpg)
45
Use Whitespace to Help the Reader
![Page 46: Peer Code Review - SE4Science · 2020. 6. 2. · Simplified Gerrit workflow 26 No Developer’s Local Branch Main project branch Reviewer Approved Developer Yes Pull to local branch](https://reader034.fdocuments.in/reader034/viewer/2022051918/600a1de45d2b3755d302736a/html5/thumbnails/46.jpg)
46
Bugs hidden in this code
![Page 47: Peer Code Review - SE4Science · 2020. 6. 2. · Simplified Gerrit workflow 26 No Developer’s Local Branch Main project branch Reviewer Approved Developer Yes Pull to local branch](https://reader034.fdocuments.in/reader034/viewer/2022051918/600a1de45d2b3755d302736a/html5/thumbnails/47.jpg)
Other Code Review Tools
![Page 48: Peer Code Review - SE4Science · 2020. 6. 2. · Simplified Gerrit workflow 26 No Developer’s Local Branch Main project branch Reviewer Approved Developer Yes Pull to local branch](https://reader034.fdocuments.in/reader034/viewer/2022051918/600a1de45d2b3755d302736a/html5/thumbnails/48.jpg)
Code Review Tools
48
Gerrit: https://code.google.com/p/gerrit/
Review Board: https://www.reviewboard.org/
Phabricator: https://phabricator.org/
Crucible: https://www.atlassian.com/software/crucible
![Page 49: Peer Code Review - SE4Science · 2020. 6. 2. · Simplified Gerrit workflow 26 No Developer’s Local Branch Main project branch Reviewer Approved Developer Yes Pull to local branch](https://reader034.fdocuments.in/reader034/viewer/2022051918/600a1de45d2b3755d302736a/html5/thumbnails/49.jpg)
Feedback And Discussion
![Page 50: Peer Code Review - SE4Science · 2020. 6. 2. · Simplified Gerrit workflow 26 No Developer’s Local Branch Main project branch Reviewer Approved Developer Yes Pull to local branch](https://reader034.fdocuments.in/reader034/viewer/2022051918/600a1de45d2b3755d302736a/html5/thumbnails/50.jpg)
Feedback
http://bit.ly/SEA-CR-Tutorial-Feedback
50
![Page 51: Peer Code Review - SE4Science · 2020. 6. 2. · Simplified Gerrit workflow 26 No Developer’s Local Branch Main project branch Reviewer Approved Developer Yes Pull to local branch](https://reader034.fdocuments.in/reader034/viewer/2022051918/600a1de45d2b3755d302736a/html5/thumbnails/51.jpg)
51
Code Review
![Page 53: Peer Code Review - SE4Science · 2020. 6. 2. · Simplified Gerrit workflow 26 No Developer’s Local Branch Main project branch Reviewer Approved Developer Yes Pull to local branch](https://reader034.fdocuments.in/reader034/viewer/2022051918/600a1de45d2b3755d302736a/html5/thumbnails/53.jpg)
Photo Credits
- http://incolors.club/collectionfdwn-female-computer-programmer.htm
- http://tech.trivago.com/img/posts/code-review/code-review-3.jpg
- http://www.protectitip.com/wp-content/uploads/2014/11/Software-Code.jpg
- http://www.computerhistory.org/atchm/wp-content/uploads/2013/11/marked_up_listing-542x404.jpg
- https://static1.squarespace.com/static/53798babe4b0fca9449cf693/t/53f78774e4b0ce4d05e4152f/1408730997720/
- https://residentialwastesystems.com/wp-content/uploads/2016/10/dumpsters-trumbull-ct.jpg• http://www.hipaasecurenow.com/index.php/beckers-
hipaa-compliance-8-best-practices/• https://commons.wikimedia.org/wiki/File:Collaborati
on_(9601759166).jpg#metadata 53