Transcript
Page 1: Code Review for Teams Too Busy to Review Code - Atlassian Summit 2010

11

Page 2: Code Review for Teams Too Busy to Review Code - Atlassian Summit 2010

A guide for chronically time-poor developers

Code Review for Busy Teams

Brendan Humphreys, Atlassian

22

Page 3: Code Review for Teams Too Busy to Review Code - Atlassian Summit 2010

Who am I?

3

• @brendanh•Team Lead, FishEye & Crucible•12+ years experience doing code review•12+ years of trying to do code review better•

3

Page 4: Code Review for Teams Too Busy to Review Code - Atlassian Summit 2010

Topics

•Back to basics•How to we got to where we are•Three steps towards code review•Strategies & hurdles•Some tips for better reviews•

44

Page 5: Code Review for Teams Too Busy to Review Code - Atlassian Summit 2010

#include <stdio.h>main(t,_,a)char *a;{return!0<t?t<3?main(-79,-13,a+main(-87,1-_,main(-86,0,a+1)+a)):1,t<_?main(t+1,_,a):3,main(-94,-27+t,a)&&t==2?_<13?main(2,_+1,"%s %d %d\n"):9:16:t<0?t<-72?main(_,t,"@n'+,#'/*{}w+/w#cdnr/+,{}r/*de}+,/*{*+,/w{%+,/w#q#n+,/#{l,+,/n{n+,/+#n+,/#\;#q#n+,/+k#;*+,/'r :'d*'3,}{w+K w'K:'+}e#';dq#'l \q#'+d'K#!/+k#;q#'r}eKK#}w'r}eKK{nl]'/#;#q#n'){)#}w'){){nl]'/+#n';d}rw' i;# \){nl]!/n{n#'; r{#w'r nc{nl]'/#{l,+'K {rw' iK{;[{nl]'/w#q#n'wk nw' \iwk{KK{nl]!/w{%'l##w#' i; :{nl]'/*{q#'ld;r'}{nlwb!/*de}'c \;;{nl'-{}rw]'/+,}##'*}#nc,',#nw]'/+kd'+e}+;#'rdq#w! nr'/ ') }+}{rl#'{n' ')# \}'+}##(!!/"):t<-50?_==*a?putchar(31[a]):main(-65,_,a+1):main((*a=='/')+t,_,a+1) :0<t?main(2,2,"%s"):*a=='/'||main(0,main(-61,*a,"!ek;dc i@bK'(q)-[w]*%n+r3#l,{}:\nuwloca-O;m .vpbks,fxntdCeghiry"),a+1);}

5

Page 6: Code Review for Teams Too Busy to Review Code - Atlassian Summit 2010

What is it that we do all day?

6

Page 7: Code Review for Teams Too Busy to Review Code - Atlassian Summit 2010

7

Page 8: Code Review for Teams Too Busy to Review Code - Atlassian Summit 2010

88

Page 9: Code Review for Teams Too Busy to Review Code - Atlassian Summit 2010

9

Page 10: Code Review for Teams Too Busy to Review Code - Atlassian Summit 2010

Req. Design Coding Testing QA Production

$$$

Relative cost of fixing a bug

10

Page 11: Code Review for Teams Too Busy to Review Code - Atlassian Summit 2010

$500 million payload

$8 billionrocket

1 line softwaredefect

11

Page 12: Code Review for Teams Too Busy to Review Code - Atlassian Summit 2010

1212

Page 13: Code Review for Teams Too Busy to Review Code - Atlassian Summit 2010

The Rise of Agile

13

Page 14: Code Review for Teams Too Busy to Review Code - Atlassian Summit 2010

14

Page 15: Code Review for Teams Too Busy to Review Code - Atlassian Summit 2010

15

Page 16: Code Review for Teams Too Busy to Review Code - Atlassian Summit 2010

16

Page 17: Code Review for Teams Too Busy to Review Code - Atlassian Summit 2010

1717

Page 18: Code Review for Teams Too Busy to Review Code - Atlassian Summit 2010

Machines vs Humans

18

Page 19: Code Review for Teams Too Busy to Review Code - Atlassian Summit 2010

blocky:~ brendan$ javac hello.java hello.java:6: cannot find symbolsymbol : variable lengthlocation: class java.lang.String for (int i = 0; i < s.length; i++) { ^1 error

19

Page 20: Code Review for Teams Too Busy to Review Code - Atlassian Summit 2010

20

Page 21: Code Review for Teams Too Busy to Review Code - Atlassian Summit 2010

21

Page 22: Code Review for Teams Too Busy to Review Code - Atlassian Summit 2010

•Checkstyle, Lint, PMD•Findbugs•Clover

22

Smarter Tools

22

Page 23: Code Review for Teams Too Busy to Review Code - Atlassian Summit 2010

Continuous Feedback

2323

Page 24: Code Review for Teams Too Busy to Review Code - Atlassian Summit 2010

Tougher Questions

•Meet requirements? •Architecturally sound?•Futureproof?•Coding idioms correct?•Potential reuse•Domain knowledge

24

CodeReview}

24

Page 25: Code Review for Teams Too Busy to Review Code - Atlassian Summit 2010

25

Page 26: Code Review for Teams Too Busy to Review Code - Atlassian Summit 2010

Code Review

•“Systematic review of code by peers”• reduce defects• spread code ownership• mentor developers

2626

Page 27: Code Review for Teams Too Busy to Review Code - Atlassian Summit 2010

Formal Code InspectionFagan, 1976

Finds Defects Early!

Printed Source code!

Rigid process,Face-to-face meetings!

Very slowImpractical for largecodebases

Great for mentoring, knowledge sharing

27

Page 28: Code Review for Teams Too Busy to Review Code - Atlassian Summit 2010

Very effective code review, finds defects early

Great for sharing knowledge,mentoring

Pair Programming

Requires two developers,co-located

Transient discussionPersonalities

28

Page 29: Code Review for Teams Too Busy to Review Code - Atlassian Summit 2010

Tool-assisted Code Review

29

•Managed workflow and notification•Record of discussion•Asynchronous•Change team culture?

29

Page 30: Code Review for Teams Too Busy to Review Code - Atlassian Summit 2010

3 steps towards a code review culture

30

•Make activity visible•Make code sharable•Encourage discussions around code

30

Page 31: Code Review for Teams Too Busy to Review Code - Atlassian Summit 2010

Making Activity Visible

31

Page 32: Code Review for Teams Too Busy to Review Code - Atlassian Summit 2010

FishEye: Unlock your repository

3232

Page 33: Code Review for Teams Too Busy to Review Code - Atlassian Summit 2010

Making Activity Visible

33

•The FishEyeActivity Stream•Web•RSS•Watches• JIRA•

33

Page 34: Code Review for Teams Too Busy to Review Code - Atlassian Summit 2010

34

Page 35: Code Review for Teams Too Busy to Review Code - Atlassian Summit 2010

Making Code Sharable

35

•FishEye makes it easy to share code pointers•File revisions•Source Lines•Diffs•ChangeSets•

35

Page 36: Code Review for Teams Too Busy to Review Code - Atlassian Summit 2010

EncouragingDiscussionsAround code

3636

Page 37: Code Review for Teams Too Busy to Review Code - Atlassian Summit 2010

Crucible: Lightweight Code Review

3737

Page 38: Code Review for Teams Too Busy to Review Code - Atlassian Summit 2010

Crucible: ChangeSet Discussions

3838

Page 39: Code Review for Teams Too Busy to Review Code - Atlassian Summit 2010

39

Page 40: Code Review for Teams Too Busy to Review Code - Atlassian Summit 2010

ChangeSet Discussions

40

•Simple way to provide ad-hoc feedback•Threaded discussions•ChangeSet author notified•Appear in Activity Stream•Preserved as annotation to ChangeSet•

40

Page 41: Code Review for Teams Too Busy to Review Code - Atlassian Summit 2010

Crucible: Snippets

4141

Page 42: Code Review for Teams Too Busy to Review Code - Atlassian Summit 2010

42

Page 43: Code Review for Teams Too Busy to Review Code - Atlassian Summit 2010

Snippets•Simple “paste-bin” service•Anyone can comment, reply, raise defect•All participants notified•Appear in activity stream•Durable, sharable

4343

Page 44: Code Review for Teams Too Busy to Review Code - Atlassian Summit 2010

Crucible: “formal” review

44

•Simple workflow• draft, review, summarize, close•Manage review workload• target particular reviewers•Advanced features• Pre-commit, Iterative, create from JIRA

44

Page 45: Code Review for Teams Too Busy to Review Code - Atlassian Summit 2010

45

Page 46: Code Review for Teams Too Busy to Review Code - Atlassian Summit 2010

How to get started

•Go slow•Just the diffs•Review the scariest code!•On demand•On assignment

4646

Page 47: Code Review for Teams Too Busy to Review Code - Atlassian Summit 2010

Common Hurdles to Adoption

•“It takes too much time”•"Code reviews can get nasty"•"We have to stick to XYZ process"•"I don't want to leave my IDE"

4747

Page 48: Code Review for Teams Too Busy to Review Code - Atlassian Summit 2010

Four tips for better reviews

4848

Page 49: Code Review for Teams Too Busy to Review Code - Atlassian Summit 2010

#1:Strive for Ego-Free Reviews

49

Page 50: Code Review for Teams Too Busy to Review Code - Atlassian Summit 2010

#1: Ego-Free Reviews

• No personal Pronouns

• No point scoring

• Moderator to police

50

Page 51: Code Review for Teams Too Busy to Review Code - Atlassian Summit 2010

#2:Don’t be a

Pedant

51

Page 52: Code Review for Teams Too Busy to Review Code - Atlassian Summit 2010

#2: Don’t be a Pedant

•Use tools to enforce coding style, catch common errors

•Look for the forest, not the trees

52

Page 53: Code Review for Teams Too Busy to Review Code - Atlassian Summit 2010

#3: Find Problems,

Not Solutions

53

Page 54: Code Review for Teams Too Busy to Review Code - Atlassian Summit 2010

#3: Find Problems, Not Solutions

• Except for trivial fixes

• Pair program instead

54

Page 55: Code Review for Teams Too Busy to Review Code - Atlassian Summit 2010

#4: Embrace Feedback55

Page 56: Code Review for Teams Too Busy to Review Code - Atlassian Summit 2010

•You will learn from it!

•You will learn to love it!

#4: Embrace Feedback

56

Page 57: Code Review for Teams Too Busy to Review Code - Atlassian Summit 2010

#include <stdio.h>main(t,_,a)char *a;{return!0<t?t<3?main(-79,-13,a+main(-87,1-_,main(-86,0,a+1)+a)):1,t<_?main(t+1,_,a):3,main(-94,-27+t,a)&&t==2?_<13?main(2,_+1,"%s %d %d\n"):9:16:t<0?t<-72?main(_,t,"@n'+,#'/*{}w+/w#cdnr/+,{}r/*de}+,/*{*+,/w{%+,/w#q#n+,/#{l,+,/n{n+,/+#n+,/#\;#q#n+,/+k#;*+,/'r :'d*'3,}{w+K w'K:'+}e#';dq#'l \q#'+d'K#!/+k#;q#'r}eKK#}w'r}eKK{nl]'/#;#q#n'){)#}w'){){nl]'/+#n';d}rw' i;# \){nl]!/n{n#'; r{#w'r nc{nl]'/#{l,+'K {rw' iK{;[{nl]'/w#q#n'wk nw' \iwk{KK{nl]!/w{%'l##w#' i; :{nl]'/*{q#'ld;r'}{nlwb!/*de}'c \;;{nl'-{}rw]'/+,}##'*}#nc,',#nw]'/+kd'+e}+;#'rdq#w! nr'/ ') }+}{rl#'{n' ')# \}'+}##(!!/"):t<-50?_==*a?putchar(31[a]):main(-65,_,a+1):main((*a=='/')+t,_,a+1) :0<t?main(2,2,"%s"):*a=='/'||main(0,main(-61,*a,"!ek;dc i@bK'(q)-[w]*%n+r3#l,{}:\nuwloca-O;m .vpbks,fxntdCeghiry"),a+1);}

57

Page 58: Code Review for Teams Too Busy to Review Code - Atlassian Summit 2010

blocky:~ brendan$ ./a.outOn the first day of Christmas my true love gave to mea partridge in a pear tree.

On the second day of Christmas my true love gave to metwo turtle dovesand a partridge in a pear tree.

On the third day of Christmas my true love gave to methree french hens, two turtle dovesand a partridge in a pear tree.

On the fourth day of Christmas my true love gave to mefour calling birds, three french hens, two turtle dovesand a partridge in a pear tree.

On the fifth day of Christmas my true love gave to mefive gold rings;four calling birds, three french hens, two turtle dovesand a partridge in a pear tree.

On the sixth day of Christmas my true love gave to mesix geese a-laying, five gold rings;four calling birds, three french hens, two turtle dovesand a partridge in a pear tree.

On the seventh day of Christmas my true love gave to meseven swans a-swimming,six geese a-laying, five gold rings;four calling birds, three french hens, two turtle dovesand a partridge in a pear tree.

On the eighth day of Christmas my true love gave to meeight maids a-milking, seven swans a-swimming,six geese a-laying, five gold rings;four calling birds, three french hens, two turtle dovesand a partridge in a pear tree.

58

Page 59: Code Review for Teams Too Busy to Review Code - Atlassian Summit 2010

#include <stdio.h>main(t,_,a)char *a;{return!0<t?t<3?main(-79,-13,a+main(-87,1-_,main(-86,0,a+1)+a)):1,t<_?main(t+1,_,a):3,main(-94,-27+t,a)&&t==2?_<13?main(2,_+1,"%s %d %d\n"):9:16:t<0?t<-72?main(_,t,"@n'+,#'/*{}w+/w#cdnr/+,{}r/*de}+,/*{*+,/w{%+,/w#q#n+,/#{l,+,/n{n+,/+#n+,/#\;#q#n+,/+k#;*+,/'r :'d*'3,}{w+K w'K:'+}e#';dq#'l \q#'+d'K#!/+k#;q#'r}eKK#}w'r}eKK{nl]'/#;#q#n'){)#}w'){){nl]'/+#n';d}rw' i;# \){nl]!/n{n#'; r{#w'r nc{nl]'/#{l,+'K {rw' iK{;[{nl]'/w#q#n'wk nw' \iwk{KK{nl]!/w{%'l##w#' i; :{nl]'/*{q#'ld;r'}{nlwb!/*de}'c \;;{nl'-{}rw]'/+,}##'*}#nc,',#nw]'/+kd'+e}+;#'rdq#w! nr'/ ') }+}{rl#'{n' ')# \}'+}##(!!/"):t<-50?_==*a?putchar(31[a]):main(-65,_,a+1):main((*a=='/')+t,_,a+1) :0<t?main(2,2,"%s"):*a=='/'||main(0,main(-61,*a,"!ek;dc i@bK'(q)-[w]*%n+r3#l,{}:\nuwloca-O;m .vpbks,fxntdCeghiry"),a+1);}

59

Page 60: Code Review for Teams Too Busy to Review Code - Atlassian Summit 2010

6060


Recommended