code review - encodo systems ag...sources – best kept secrets of peer code review jason cohen in...

51
Code Review Best practices

Upload: others

Post on 28-Feb-2021

3 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Code Review - Encodo Systems AG...Sources – Best Kept Secrets of Peer Code Review Jason Cohen in 2006 – Expectations, Outcomes, and Challenges of modern Code Review Alberto Bacchelli

Code

Review

Best practices

Page 2: Code Review - Encodo Systems AG...Sources – Best Kept Secrets of Peer Code Review Jason Cohen in 2006 – Expectations, Outcomes, and Challenges of modern Code Review Alberto Bacchelli

Why are we

talking about it?

Page 3: Code Review - Encodo Systems AG...Sources – Best Kept Secrets of Peer Code Review Jason Cohen in 2006 – Expectations, Outcomes, and Challenges of modern Code Review Alberto Bacchelli

Not useful to spread know how

Not a good way to mentor juniors

Out of office commits not reviewed

Feeling it is not done seriously

Encodo Perception

Page 4: Code Review - Encodo Systems AG...Sources – Best Kept Secrets of Peer Code Review Jason Cohen in 2006 – Expectations, Outcomes, and Challenges of modern Code Review Alberto Bacchelli

Benefits

Page 5: Code Review - Encodo Systems AG...Sources – Best Kept Secrets of Peer Code Review Jason Cohen in 2006 – Expectations, Outcomes, and Challenges of modern Code Review Alberto Bacchelli

The Ego Effect

Benefits

Page 6: Code Review - Encodo Systems AG...Sources – Best Kept Secrets of Peer Code Review Jason Cohen in 2006 – Expectations, Outcomes, and Challenges of modern Code Review Alberto Bacchelli

Why we were talking about it

Finding Bugs

Page 7: Code Review - Encodo Systems AG...Sources – Best Kept Secrets of Peer Code Review Jason Cohen in 2006 – Expectations, Outcomes, and Challenges of modern Code Review Alberto Bacchelli

Early Fixing

Page 8: Code Review - Encodo Systems AG...Sources – Best Kept Secrets of Peer Code Review Jason Cohen in 2006 – Expectations, Outcomes, and Challenges of modern Code Review Alberto Bacchelli

The Ego Effect

Team Awareness and Transparency

Finding alternative Solutions to Problems

Code Improvement

Benefits

Page 9: Code Review - Encodo Systems AG...Sources – Best Kept Secrets of Peer Code Review Jason Cohen in 2006 – Expectations, Outcomes, and Challenges of modern Code Review Alberto Bacchelli

«the discipline of explaining your code to your peers»

Expectations, Outcomes, and Challenges of modern Code Review

Benefits

Page 10: Code Review - Encodo Systems AG...Sources – Best Kept Secrets of Peer Code Review Jason Cohen in 2006 – Expectations, Outcomes, and Challenges of modern Code Review Alberto Bacchelli

Technical

Discussions

Page 11: Code Review - Encodo Systems AG...Sources – Best Kept Secrets of Peer Code Review Jason Cohen in 2006 – Expectations, Outcomes, and Challenges of modern Code Review Alberto Bacchelli

The Ego Effect

Team Awareness and Transparency

Finding alternative Solutions to Problems

Code Improvement

Knowledge Transfer (Increased Bus Factor)

Finding Defects

Benefits

Page 12: Code Review - Encodo Systems AG...Sources – Best Kept Secrets of Peer Code Review Jason Cohen in 2006 – Expectations, Outcomes, and Challenges of modern Code Review Alberto Bacchelli

Costs developer Time

Interruptions cost time

No quality assurance measure

-> A creating quality measure

Drawbacks

Page 13: Code Review - Encodo Systems AG...Sources – Best Kept Secrets of Peer Code Review Jason Cohen in 2006 – Expectations, Outcomes, and Challenges of modern Code Review Alberto Bacchelli

Types

Page 14: Code Review - Encodo Systems AG...Sources – Best Kept Secrets of Peer Code Review Jason Cohen in 2006 – Expectations, Outcomes, and Challenges of modern Code Review Alberto Bacchelli
Page 15: Code Review - Encodo Systems AG...Sources – Best Kept Secrets of Peer Code Review Jason Cohen in 2006 – Expectations, Outcomes, and Challenges of modern Code Review Alberto Bacchelli

Formal Inspection

Pair Programming

Over the shoulder

Tool Based

Types

Page 16: Code Review - Encodo Systems AG...Sources – Best Kept Secrets of Peer Code Review Jason Cohen in 2006 – Expectations, Outcomes, and Challenges of modern Code Review Alberto Bacchelli

Practice lightweight code reviews

Face to Face, Said, Sync

vs.

Tool, Written, Async

Types – Best Practices

Page 17: Code Review - Encodo Systems AG...Sources – Best Kept Secrets of Peer Code Review Jason Cohen in 2006 – Expectations, Outcomes, and Challenges of modern Code Review Alberto Bacchelli

Best

Practices

Page 18: Code Review - Encodo Systems AG...Sources – Best Kept Secrets of Peer Code Review Jason Cohen in 2006 – Expectations, Outcomes, and Challenges of modern Code Review Alberto Bacchelli

Less than ??? lines of code

Best Practices – In Numbers

Page 19: Code Review - Encodo Systems AG...Sources – Best Kept Secrets of Peer Code Review Jason Cohen in 2006 – Expectations, Outcomes, and Challenges of modern Code Review Alberto Bacchelli

Less than 400 lines of code

Best Practices – In Numbers

Page 20: Code Review - Encodo Systems AG...Sources – Best Kept Secrets of Peer Code Review Jason Cohen in 2006 – Expectations, Outcomes, and Challenges of modern Code Review Alberto Bacchelli

Less than 400 lines of code

Not more than ??? loc / hour

Best Practices – In Numbers

Page 21: Code Review - Encodo Systems AG...Sources – Best Kept Secrets of Peer Code Review Jason Cohen in 2006 – Expectations, Outcomes, and Challenges of modern Code Review Alberto Bacchelli

Less than 400 lines of code

Go Slow, not more than 500 loc / hour

Best Practices – In Numbers

Page 22: Code Review - Encodo Systems AG...Sources – Best Kept Secrets of Peer Code Review Jason Cohen in 2006 – Expectations, Outcomes, and Challenges of modern Code Review Alberto Bacchelli

Less than 400 lines of code

Go Slow, not more than 500 loc / hour

Maximum of ??? minutes

Best Practices – In Numbers

Page 23: Code Review - Encodo Systems AG...Sources – Best Kept Secrets of Peer Code Review Jason Cohen in 2006 – Expectations, Outcomes, and Challenges of modern Code Review Alberto Bacchelli

Less than 400 lines of code

Go Slow, not more than 500 loc / hour

Maximum of 60 minutes

Best Practices – In Numbers

Page 24: Code Review - Encodo Systems AG...Sources – Best Kept Secrets of Peer Code Review Jason Cohen in 2006 – Expectations, Outcomes, and Challenges of modern Code Review Alberto Bacchelli

Less than 400 lines of code

Go Slow, not more than 500 loc / hour

Maximum of 60 minutes

Maximum of ??? reviewers

Best Practices - In Numbers

Page 25: Code Review - Encodo Systems AG...Sources – Best Kept Secrets of Peer Code Review Jason Cohen in 2006 – Expectations, Outcomes, and Challenges of modern Code Review Alberto Bacchelli

Less than 400 lines of code

Go Slow, not more than 500 loc / hour

Maximum of 60 minutes

Maximum of 2 reviewers

Best Practices - In Numbers

Page 26: Code Review - Encodo Systems AG...Sources – Best Kept Secrets of Peer Code Review Jason Cohen in 2006 – Expectations, Outcomes, and Challenges of modern Code Review Alberto Bacchelli

In a

hurry?

Page 27: Code Review - Encodo Systems AG...Sources – Best Kept Secrets of Peer Code Review Jason Cohen in 2006 – Expectations, Outcomes, and Challenges of modern Code Review Alberto Bacchelli

Due to selected code parts

– Just the Diffs

– Just the Scariest Code

– Only Unit Tests

On demand

– E.g. Feature Freeze

– Triggered by Developer

Best Practices – Getting Faster

Page 28: Code Review - Encodo Systems AG...Sources – Best Kept Secrets of Peer Code Review Jason Cohen in 2006 – Expectations, Outcomes, and Challenges of modern Code Review Alberto Bacchelli

Use Tooling - Formatter, Compiler, Metrics, …

– Modern IDE + Extensions

– Continuous Integration

Collect Commits

Practice

Best Practices – Getting Faster

Page 29: Code Review - Encodo Systems AG...Sources – Best Kept Secrets of Peer Code Review Jason Cohen in 2006 – Expectations, Outcomes, and Challenges of modern Code Review Alberto Bacchelli

How

Page 30: Code Review - Encodo Systems AG...Sources – Best Kept Secrets of Peer Code Review Jason Cohen in 2006 – Expectations, Outcomes, and Challenges of modern Code Review Alberto Bacchelli

How!

Page 31: Code Review - Encodo Systems AG...Sources – Best Kept Secrets of Peer Code Review Jason Cohen in 2006 – Expectations, Outcomes, and Challenges of modern Code Review Alberto Bacchelli

Review it yourself

How - Author

Page 32: Code Review - Encodo Systems AG...Sources – Best Kept Secrets of Peer Code Review Jason Cohen in 2006 – Expectations, Outcomes, and Challenges of modern Code Review Alberto Bacchelli

How – by Understanding

Page 33: Code Review - Encodo Systems AG...Sources – Best Kept Secrets of Peer Code Review Jason Cohen in 2006 – Expectations, Outcomes, and Challenges of modern Code Review Alberto Bacchelli

Review it yourself

Provide Context and Design Rational

– Proposal: 2 Paragraphs in Commit Message

How - Author

Page 34: Code Review - Encodo Systems AG...Sources – Best Kept Secrets of Peer Code Review Jason Cohen in 2006 – Expectations, Outcomes, and Challenges of modern Code Review Alberto Bacchelli

Discussion

Page 35: Code Review - Encodo Systems AG...Sources – Best Kept Secrets of Peer Code Review Jason Cohen in 2006 – Expectations, Outcomes, and Challenges of modern Code Review Alberto Bacchelli

Review it yourself

Provide Context and Design Rational

– 2 Paragraphs in Commit Message

Embrace Feedback - Give it a thought

How - Author

Page 36: Code Review - Encodo Systems AG...Sources – Best Kept Secrets of Peer Code Review Jason Cohen in 2006 – Expectations, Outcomes, and Challenges of modern Code Review Alberto Bacchelli

Generalizing

- Always use this… / Never do that…

+ Can you show me what you mean?

How - Reviewer

Page 37: Code Review - Encodo Systems AG...Sources – Best Kept Secrets of Peer Code Review Jason Cohen in 2006 – Expectations, Outcomes, and Challenges of modern Code Review Alberto Bacchelli

Generalizing

- Always use this… / Never do that…

+ Can you show me what you mean?

Ask don't tell

+ What do you think about …?

+ Did you consider…?

+ Can you clarify … ? (What the hell is going on here)

How - Reviewer

Page 38: Code Review - Encodo Systems AG...Sources – Best Kept Secrets of Peer Code Review Jason Cohen in 2006 – Expectations, Outcomes, and Challenges of modern Code Review Alberto Bacchelli

Guessing Game

- How can we make this better?

+ I feel confused. Where should we start?

Negative Questions

- Why didn’t you just …?

+ Be positive

How – Question everything?

Page 39: Code Review - Encodo Systems AG...Sources – Best Kept Secrets of Peer Code Review Jason Cohen in 2006 – Expectations, Outcomes, and Challenges of modern Code Review Alberto Bacchelli

Conflict

Page 40: Code Review - Encodo Systems AG...Sources – Best Kept Secrets of Peer Code Review Jason Cohen in 2006 – Expectations, Outcomes, and Challenges of modern Code Review Alberto Bacchelli

Insist on high quality reviews

-> But agree to disagree

Handle disagreement

How - Conflict

Page 41: Code Review - Encodo Systems AG...Sources – Best Kept Secrets of Peer Code Review Jason Cohen in 2006 – Expectations, Outcomes, and Challenges of modern Code Review Alberto Bacchelli

What?

Page 42: Code Review - Encodo Systems AG...Sources – Best Kept Secrets of Peer Code Review Jason Cohen in 2006 – Expectations, Outcomes, and Challenges of modern Code Review Alberto Bacchelli

General- and business logic

Architecture and design

Readability and maintainability

Performance

Security

What

Page 43: Code Review - Encodo Systems AG...Sources – Best Kept Secrets of Peer Code Review Jason Cohen in 2006 – Expectations, Outcomes, and Challenges of modern Code Review Alberto Bacchelli

General- and business logic

Architecture and design

Readability and maintainability

Performance

Security

What

Page 44: Code Review - Encodo Systems AG...Sources – Best Kept Secrets of Peer Code Review Jason Cohen in 2006 – Expectations, Outcomes, and Challenges of modern Code Review Alberto Bacchelli

Checklists

Personal Checklists

What

Page 45: Code Review - Encodo Systems AG...Sources – Best Kept Secrets of Peer Code Review Jason Cohen in 2006 – Expectations, Outcomes, and Challenges of modern Code Review Alberto Bacchelli

Checklists

Personal Checklists

Encodo experience

What

Page 46: Code Review - Encodo Systems AG...Sources – Best Kept Secrets of Peer Code Review Jason Cohen in 2006 – Expectations, Outcomes, and Challenges of modern Code Review Alberto Bacchelli

What do you

value?

Page 47: Code Review - Encodo Systems AG...Sources – Best Kept Secrets of Peer Code Review Jason Cohen in 2006 – Expectations, Outcomes, and Challenges of modern Code Review Alberto Bacchelli

Here

Page 48: Code Review - Encodo Systems AG...Sources – Best Kept Secrets of Peer Code Review Jason Cohen in 2006 – Expectations, Outcomes, and Challenges of modern Code Review Alberto Bacchelli

Encodo Code Review Process

Page 49: Code Review - Encodo Systems AG...Sources – Best Kept Secrets of Peer Code Review Jason Cohen in 2006 – Expectations, Outcomes, and Challenges of modern Code Review Alberto Bacchelli

Author shall pick appropriate Reviewer

Not over 1h

Not more than 200 loc at once to review

Small Commits, Avoid big code changes

If you still happen to have a big change, only sync Face to Face reviews!

Encodo Best practice constraints

Page 50: Code Review - Encodo Systems AG...Sources – Best Kept Secrets of Peer Code Review Jason Cohen in 2006 – Expectations, Outcomes, and Challenges of modern Code Review Alberto Bacchelli

Foster Strong Review

Culture

Page 51: Code Review - Encodo Systems AG...Sources – Best Kept Secrets of Peer Code Review Jason Cohen in 2006 – Expectations, Outcomes, and Challenges of modern Code Review Alberto Bacchelli

Sources– Best Kept Secrets of Peer Code Review

Jason Cohen in 2006

– Expectations, Outcomes, and Challenges of modern Code Review

Alberto Bacchelli and Christian Bird, May 2013

http://research.microsoft.com/apps/pubs/default.aspx?id=180283

– best-practices-for-peer-code-reviewhttps://smartbear.com/learn/code-review/best-practices-for-peer-code-review/

– Better Code Review https://www.youtube.com/watch?v=rHVlFOB5BpU

– RailsConf 2015 - Implementing a Strong Code-Review Culture

https://www.youtube.com/watch?v=PJjmw9TRB7s

– How to stop wasting your time and start performing useful code reviews by Maria Khalusova, jetbrains

https://www.youtube.com/watch?v=VRnMzMpSeag

– 11 Best Practices for Peer Code Review - IBM Innovate Conference 2011

Jason Cohen - Author of "Best kept Secrets of Peer Code Review"

https://www.youtube.com/watch?v=hgNAwAdhwoQ

– Code Review for Teams Too Busy to Review CodeBrandan Humphreys, Atlassian

https://www.youtube.com/watch?v=1m3eRFeCInY

Images• https://www.flickr.com/photos/mongogushi/

• https://www.flickr.com/photos/jwhitesmith/

• https://www.flickr.com/photos/mwichary/

• https://www.flickr.com/photos/bike/

• https://www.flickr.com/photos/michaelpardo/

• https://www.flickr.com/photos/sreichenbach/

• http://pcweenies.com/comic/oreville-and-bugs

• https://www.flickr.com/photos/unlistedsightings/

• https://www.flickr.com/photos/joncandy/

Diagrams• https://support.smartbear.com/support/media/re

sources/cc/Episode_1_TheCaseForCodeReview.pdf

• http://research.microsoft.com/pubs/180283/ICSE%202013-codereview.pdf

• Encodo Wiki

Sources