SlideShare a Scribd company logo
1 of 28
Download to read offline
CODE REVIEW
BEST PRACTICES
OREN DIGMI | FEB 2018
2
Code review is a very important part
of the software development cycle.
We are using pull requests to review
code on branches before it reaches
dev.
Code review is one of the most
difficult and time consuming part of
the software development process.
What is Code Review?
1
2
3
“No problem can be solved from the same
level of consciousness that created it”
3
Albert Einstein
Why reviewing code?
4
● Saving time and money. by finding bugs in early stage.
● Sharing knowledge across the team, no single
developer in the critical path.
● Team cohesion. encourage developer to talk each
other and bring them closer to each other.
● Coding standard. helps to maintain consistent coding
style across the team.
INSTRUCTIONS
5
6
Before submitting a pull request
COMPILE
The code is not broken, should successful
compile and build.
COVERAGE
All code in codebase should be tested, the
coverage should not decrease by merging your
code.
Tests
Your tests code should run successfully and
pass travis run.
READY
Your code should be ready for PR, DO NOT assign
reviewer to your PR if it’s not completely ready.
JIRA
Linked to the relevant JIRA item (PR
name should start with the JIRA number)
Pull request example
7
Reviewing pull requests is HARD
8
● To make sure that the
code is correct and of high
quality.
● Review for core logic and
architecture aspects.
● Review for adequate test
coverage.
The reviewer responsible for
the code reviewed by him!
Reviewer
responsibility
9
Code Review Guidelines
10
Preparing your code for review
11
Communicate with your reviewer
Give your reviewers background about your task.
Create Pull Request with a reasonable timeframes. Take into consideration the reviewer status, time for
reviewer to understand the code and goals, bugs and code refactoring.
Give your reviewers context on your change. Ideally, you should speak with them before any non-trivial
review or document the changes you’re making inside of the review’s description.
Make sure to summarize the change you’re making, why you are making those changes, and link to a
ticket or spec to provide any additional context.
Since most of us pull request authors have likely been reviewers already, simply put yourself in the shoes
of the reviewer and ask, “How could this be easier for me?”
12
Guidelines / Preparing your code review
Make smaller pull requests
Making smaller pull requests is the best way to speed up your review time. Keep your pull requests small
so that you can iterate more quickly and accurately. In general, smaller code changes are also easier to
test and verify as stable. When pull request is small, it’s easier for the reviewers to understand the
context and reason with the logic.
According to review study (see figure) the optimal effectiveness, developers should review fewer than
200-400 lines of code (LOC) at a time. Beyond that, the ability to find defects diminishes.
Reviewing 200-400 lines of code over 60-90 minutes, should yield 70-90% defect discovery.
Reading beyond 400 lines of code, the ability to find defects diminishes.
13
Guidelines / Preparing your code review
Make smaller pull requests
14
Guidelines / Preparing your code review
defect density dramatically decreases when the number of lines of inspection goes above 200, and it is almost zero after 400
Make your code easy to review- useful description
Writing a useful description for your pull request can almost be as effective as making a smaller pull
request. Make sure to provide helpful descriptions. The most helpful descriptions guide the reviewer
through the code as much as possible, highlighting related files and grouping them into concepts or
problems that are being solved. This saves the reviewer a lot of time because they don’t have to read
every file to try and group them up and identify related concepts.
15
Guidelines / Preparing your code review
Make your code easy to review- comments
Code should contain both high-level and in-line comments. High-level comments explain how all the
components fit together and how it handles any exceptional cases while in-line comments describe why
the code takes its current shape. This will make your code easier to understand for maintainers and
reviewers.
16
Guidelines / Preparing your code review
Read and annotate your code before you sent it to review
Before submitting for review, you should review your own diff for errors. Try to do this through the eyes of
someone who has never seen the code before. Look for any decisions that may cause confusion and may need
preemptive explanation. If you feel the code is too confusing, you may want to further refine your code before
sending it out for review. Catching these issues early will save both you and the reviewers time.
You should also annotate code before the review occurs because annotations guide the reviewer through the
changes, showing which files to look at first and defending the reason behind each code modification.
Annotations should be directed at other reviewers to ease the process and provide more depth in context. As an
added benefit, the author will often find additional errors before the review even begins. More bugs found prior to
review will yield in lower defect density because fewer bugs exist overall.
Another very important issue which is often under-rated is naming. Are packages, classes, methods and variables
in your view, optimally named? do you understand all the names?
17
Guidelines / Preparing your code review
Use this Checklist
● Am I having difficulty in understanding this code?
● Is there any complexity in the code which could be reduced by refactoring?
● Is the code well organized in a package structure which makes sense?
● Are the class names intuitive and is it obvious what they do?
● Are there any classes which are notably large?
● Are there any particularly long methods?
● Do all the method names seem clear and intuitive?
● Is the code well documented?
● Is the code well tested?
● Are there ways in which this code could be made more efficient?
● Style check your code.
18
Guidelines / Preparing your code review
During a code review
19
Avoid changes during the code review
Major changes in the middle of code review basically resets the entire review process. If you need to
make major changes after submitting a review, you may want to ship your existing review and follow-up
with additional changes. If you need to make major changes after starting the code review process, make
sure to communicate this to the reviewer as early in the process as possible.
20
Guidelines / During a code review
Respond to all actionable code review feedback
You should understand every piece of feedback from your reviewer and respond to each actionable
piece. Even if you don’t implement their feedback, respond to it and explain your reasoning. If there’s
something you don’t understand, ask questions inside or outside the code review.
21
Guidelines / During a code review
Code reviews are discussions, not dictation
You can think of most code review feedback as a suggestion more than an order. It’s fine to disagree with
a reviewer’s feedback but you need to explain why and give them an opportunity to respond.
22
Guidelines / During a code review
When doing a code review
23
Understand the code and requirements
Reviewer should:
● Be aware to the task description and requirements.
● Make sure you completely understand the code.
● Evaluate all the architecture tradeoffs.
24
Guidelines / When doing a code review
Check code on many aspects
1. Verify the code correctness.
* The code is bug-free .
* The code does what it was intended to do.
* Leak memory, etc.
2. Check code quality .
* Make sure the code is maintainable.
* Check the code is general as it need to be and well organized.
* Is there a better way to accomplish the goal?
* Style issues- not consistent with the rest of the codebase.
3. Verify the code is well tested.
* All code in codebase should be tested.
* Tests are written according Gett guidelines Writing Golang tests
* Make sure unit tests are isolated, don’t have unnecessary dependencies and testing the right things.
* Confirm adequate test coverage.
4. Make sure the code is safe to deploy.
* Ask if the code is forwards/backwards compatible.
* Run through a roll-back scenario to check for rollback safety.
* Dependencies with other services? 25
Guidelines / When doing a code review
Avoid many comments and use github review
When you have several comments you should use the review option in github, instead of comment each of them
separately, and notify the developer (PR owner) when you finished.
This will prevent confusion and providing clearly stated when the review ends.
26
Guidelines / When doing a code review
Comments level
Another best practice is divide your comments for 3 categories:
1. Critical:
Comments that the developer must to accept and change the code:
Examples: bug, wrong logic, memory leak etc.
2. Optional:
Recommends for the developer for changes, nice to have but not mandatory.
3. Positive Comment:
When you find nice piece of code, let the developer know your appreciation
27
Guidelines / When doing a code review
THANK YOU
28

More Related Content

What's hot

An overview of selenium webdriver
An overview of selenium webdriverAn overview of selenium webdriver
An overview of selenium webdriverAnuraj S.L
 
Non functional requirements. do we really care…?
Non functional requirements. do we really care…?Non functional requirements. do we really care…?
Non functional requirements. do we really care…?OSSCube
 
Continuous Integration
Continuous IntegrationContinuous Integration
Continuous Integrationdrluckyspin
 
Peer Code Review An Agile Process
Peer Code Review An Agile ProcessPeer Code Review An Agile Process
Peer Code Review An Agile Processgsporar
 
DevOps Real-Time Projects | Edureka
DevOps Real-Time Projects | EdurekaDevOps Real-Time Projects | Edureka
DevOps Real-Time Projects | EdurekaEdureka!
 
Introduction to DevOps
Introduction to DevOpsIntroduction to DevOps
Introduction to DevOpsMatthew David
 
Transforming Organizations with CI/CD
Transforming Organizations with CI/CDTransforming Organizations with CI/CD
Transforming Organizations with CI/CDCprime
 
Jira Basic Concepts
Jira Basic ConceptsJira Basic Concepts
Jira Basic ConceptsMAKSTraining
 
Introduction to CICD
Introduction to CICDIntroduction to CICD
Introduction to CICDKnoldus Inc.
 
Code Review for Teams Too Busy to Review Code - Atlassian Summit 2010
Code Review for Teams Too Busy to Review Code - Atlassian Summit 2010Code Review for Teams Too Busy to Review Code - Atlassian Summit 2010
Code Review for Teams Too Busy to Review Code - Atlassian Summit 2010Atlassian
 
Introduction to Team Foundation Server (TFS) Online
Introduction to Team Foundation Server (TFS) OnlineIntroduction to Team Foundation Server (TFS) Online
Introduction to Team Foundation Server (TFS) OnlineDenis Voituron
 
Continuous integration
Continuous integrationContinuous integration
Continuous integrationamscanne
 
Making Continuous Security a Reality with OWASP’s AppSec Pipeline - Matt Tesa...
Making Continuous Security a Reality with OWASP’s AppSec Pipeline - Matt Tesa...Making Continuous Security a Reality with OWASP’s AppSec Pipeline - Matt Tesa...
Making Continuous Security a Reality with OWASP’s AppSec Pipeline - Matt Tesa...Matt Tesauro
 
Migrating .NET Application to .NET Core
Migrating .NET Application to .NET CoreMigrating .NET Application to .NET Core
Migrating .NET Application to .NET CoreBaris Ceviz
 

What's hot (20)

QSpiders - Automation using Selenium
QSpiders - Automation using SeleniumQSpiders - Automation using Selenium
QSpiders - Automation using Selenium
 
An overview of selenium webdriver
An overview of selenium webdriverAn overview of selenium webdriver
An overview of selenium webdriver
 
Introduction to Agile Testing
Introduction to Agile TestingIntroduction to Agile Testing
Introduction to Agile Testing
 
Non functional requirements. do we really care…?
Non functional requirements. do we really care…?Non functional requirements. do we really care…?
Non functional requirements. do we really care…?
 
Continuous Integration
Continuous IntegrationContinuous Integration
Continuous Integration
 
Cypress Automation
Cypress  AutomationCypress  Automation
Cypress Automation
 
Peer Code Review An Agile Process
Peer Code Review An Agile ProcessPeer Code Review An Agile Process
Peer Code Review An Agile Process
 
DevOps Real-Time Projects | Edureka
DevOps Real-Time Projects | EdurekaDevOps Real-Time Projects | Edureka
DevOps Real-Time Projects | Edureka
 
Introduction to DevOps
Introduction to DevOpsIntroduction to DevOps
Introduction to DevOps
 
Jira Training
Jira TrainingJira Training
Jira Training
 
Transforming Organizations with CI/CD
Transforming Organizations with CI/CDTransforming Organizations with CI/CD
Transforming Organizations with CI/CD
 
Cucumber ppt
Cucumber pptCucumber ppt
Cucumber ppt
 
Jira Basic Concepts
Jira Basic ConceptsJira Basic Concepts
Jira Basic Concepts
 
Introduction to CICD
Introduction to CICDIntroduction to CICD
Introduction to CICD
 
Code Review for Teams Too Busy to Review Code - Atlassian Summit 2010
Code Review for Teams Too Busy to Review Code - Atlassian Summit 2010Code Review for Teams Too Busy to Review Code - Atlassian Summit 2010
Code Review for Teams Too Busy to Review Code - Atlassian Summit 2010
 
Introduction to Team Foundation Server (TFS) Online
Introduction to Team Foundation Server (TFS) OnlineIntroduction to Team Foundation Server (TFS) Online
Introduction to Team Foundation Server (TFS) Online
 
Continuous integration
Continuous integrationContinuous integration
Continuous integration
 
Making Continuous Security a Reality with OWASP’s AppSec Pipeline - Matt Tesa...
Making Continuous Security a Reality with OWASP’s AppSec Pipeline - Matt Tesa...Making Continuous Security a Reality with OWASP’s AppSec Pipeline - Matt Tesa...
Making Continuous Security a Reality with OWASP’s AppSec Pipeline - Matt Tesa...
 
Introduction to DevSecOps
Introduction to DevSecOpsIntroduction to DevSecOps
Introduction to DevSecOps
 
Migrating .NET Application to .NET Core
Migrating .NET Application to .NET CoreMigrating .NET Application to .NET Core
Migrating .NET Application to .NET Core
 

Similar to Code review best practice

code_review_checklist_6_actions_to_improve_the_quality_of_your_reviews.pptx
code_review_checklist_6_actions_to_improve_the_quality_of_your_reviews.pptxcode_review_checklist_6_actions_to_improve_the_quality_of_your_reviews.pptx
code_review_checklist_6_actions_to_improve_the_quality_of_your_reviews.pptxsarah david
 
code_review_checklist_6_actions_to_improve_the_quality_of_your_reviews.pdf
code_review_checklist_6_actions_to_improve_the_quality_of_your_reviews.pdfcode_review_checklist_6_actions_to_improve_the_quality_of_your_reviews.pdf
code_review_checklist_6_actions_to_improve_the_quality_of_your_reviews.pdfsarah david
 
Expert Code Review best practices
Expert Code Review best practicesExpert Code Review best practices
Expert Code Review best practicesjeetendra mandal
 
Code Review
Code ReviewCode Review
Code ReviewRavi Raj
 
Capability Building for Cyber Defense: Software Walk through and Screening
Capability Building for Cyber Defense: Software Walk through and Screening Capability Building for Cyber Defense: Software Walk through and Screening
Capability Building for Cyber Defense: Software Walk through and Screening Maven Logix
 
Automated Code Reviews with AI and ML - DevOps Next
Automated Code Reviews with AI and ML - DevOps NextAutomated Code Reviews with AI and ML - DevOps Next
Automated Code Reviews with AI and ML - DevOps NextPerfecto by Perforce
 
Software Development Standard Operating Procedure
Software Development Standard Operating Procedure Software Development Standard Operating Procedure
Software Development Standard Operating Procedure rupeshchanchal
 
Code review
Code reviewCode review
Code reviewdqpi
 
Code-Review-Principles-Process-and-Tools (1)
Code-Review-Principles-Process-and-Tools (1)Code-Review-Principles-Process-and-Tools (1)
Code-Review-Principles-Process-and-Tools (1)Aditya Bhuyan
 
An Introduction To Software Development - Implementation
An Introduction To Software Development - ImplementationAn Introduction To Software Development - Implementation
An Introduction To Software Development - ImplementationBlue Elephant Consulting
 
Testers in product development code review phase
Testers in product development   code review phaseTesters in product development   code review phase
Testers in product development code review phaseChetan Giridhar
 
Test driven development
Test driven developmentTest driven development
Test driven developmentLuis Goldster
 
Test driven development
Test driven developmentTest driven development
Test driven developmentTony Nguyen
 
Test driven development
Test driven developmentTest driven development
Test driven developmentYoung Alista
 
Test driven development
Test driven developmentTest driven development
Test driven developmentJames Wong
 
Test driven development
Test driven developmentTest driven development
Test driven developmentFraboni Ec
 
Test driven development
Test driven developmentTest driven development
Test driven developmentHarry Potter
 

Similar to Code review best practice (20)

code_review_checklist_6_actions_to_improve_the_quality_of_your_reviews.pptx
code_review_checklist_6_actions_to_improve_the_quality_of_your_reviews.pptxcode_review_checklist_6_actions_to_improve_the_quality_of_your_reviews.pptx
code_review_checklist_6_actions_to_improve_the_quality_of_your_reviews.pptx
 
code_review_checklist_6_actions_to_improve_the_quality_of_your_reviews.pdf
code_review_checklist_6_actions_to_improve_the_quality_of_your_reviews.pdfcode_review_checklist_6_actions_to_improve_the_quality_of_your_reviews.pdf
code_review_checklist_6_actions_to_improve_the_quality_of_your_reviews.pdf
 
Expert Code Review best practices
Expert Code Review best practicesExpert Code Review best practices
Expert Code Review best practices
 
Code Review
Code ReviewCode Review
Code Review
 
Unit iv
Unit ivUnit iv
Unit iv
 
Capability Building for Cyber Defense: Software Walk through and Screening
Capability Building for Cyber Defense: Software Walk through and Screening Capability Building for Cyber Defense: Software Walk through and Screening
Capability Building for Cyber Defense: Software Walk through and Screening
 
Automated Code Reviews with AI and ML - DevOps Next
Automated Code Reviews with AI and ML - DevOps NextAutomated Code Reviews with AI and ML - DevOps Next
Automated Code Reviews with AI and ML - DevOps Next
 
Software Development Standard Operating Procedure
Software Development Standard Operating Procedure Software Development Standard Operating Procedure
Software Development Standard Operating Procedure
 
Code review
Code reviewCode review
Code review
 
Code quality
Code quality Code quality
Code quality
 
Code-Review-Principles-Process-and-Tools (1)
Code-Review-Principles-Process-and-Tools (1)Code-Review-Principles-Process-and-Tools (1)
Code-Review-Principles-Process-and-Tools (1)
 
An Introduction To Software Development - Implementation
An Introduction To Software Development - ImplementationAn Introduction To Software Development - Implementation
An Introduction To Software Development - Implementation
 
Testers in product development code review phase
Testers in product development   code review phaseTesters in product development   code review phase
Testers in product development code review phase
 
SE2_Lec 18_ Coding
SE2_Lec 18_ CodingSE2_Lec 18_ Coding
SE2_Lec 18_ Coding
 
Test driven development
Test driven developmentTest driven development
Test driven development
 
Test driven development
Test driven developmentTest driven development
Test driven development
 
Test driven development
Test driven developmentTest driven development
Test driven development
 
Test driven development
Test driven developmentTest driven development
Test driven development
 
Test driven development
Test driven developmentTest driven development
Test driven development
 
Test driven development
Test driven developmentTest driven development
Test driven development
 

Recently uploaded

CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdfCCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdfAsst.prof M.Gokilavani
 
pipeline in computer architecture design
pipeline in computer architecture  designpipeline in computer architecture  design
pipeline in computer architecture designssuser87fa0c1
 
Biology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxBiology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxDeepakSakkari2
 
Arduino_CSE ece ppt for working and principal of arduino.ppt
Arduino_CSE ece ppt for working and principal of arduino.pptArduino_CSE ece ppt for working and principal of arduino.ppt
Arduino_CSE ece ppt for working and principal of arduino.pptSAURABHKUMAR892774
 
Artificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxArtificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxbritheesh05
 
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerAnamika Sarkar
 
Concrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxConcrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxKartikeyaDwivedi3
 
Application of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptxApplication of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptx959SahilShah
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVRajaP95
 
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfCCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfAsst.prof M.Gokilavani
 
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ
 
Introduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptxIntroduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptxk795866
 
Churning of Butter, Factors affecting .
Churning of Butter, Factors affecting  .Churning of Butter, Factors affecting  .
Churning of Butter, Factors affecting .Satyam Kumar
 
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort serviceGurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort servicejennyeacort
 
Heart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxHeart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxPoojaBan
 

Recently uploaded (20)

CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdfCCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
 
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCRCall Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
 
pipeline in computer architecture design
pipeline in computer architecture  designpipeline in computer architecture  design
pipeline in computer architecture design
 
Biology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxBiology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptx
 
young call girls in Green Park🔝 9953056974 🔝 escort Service
young call girls in Green Park🔝 9953056974 🔝 escort Serviceyoung call girls in Green Park🔝 9953056974 🔝 escort Service
young call girls in Green Park🔝 9953056974 🔝 escort Service
 
Arduino_CSE ece ppt for working and principal of arduino.ppt
Arduino_CSE ece ppt for working and principal of arduino.pptArduino_CSE ece ppt for working and principal of arduino.ppt
Arduino_CSE ece ppt for working and principal of arduino.ppt
 
Artificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxArtificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptx
 
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
 
Concrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxConcrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptx
 
Application of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptxApplication of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptx
 
POWER SYSTEMS-1 Complete notes examples
POWER SYSTEMS-1 Complete notes  examplesPOWER SYSTEMS-1 Complete notes  examples
POWER SYSTEMS-1 Complete notes examples
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
 
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfCCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
 
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
 
Introduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptxIntroduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptx
 
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Serviceyoung call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
 
Churning of Butter, Factors affecting .
Churning of Butter, Factors affecting  .Churning of Butter, Factors affecting  .
Churning of Butter, Factors affecting .
 
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort serviceGurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
 
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptxExploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
 
Heart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxHeart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptx
 

Code review best practice

  • 2. 2 Code review is a very important part of the software development cycle. We are using pull requests to review code on branches before it reaches dev. Code review is one of the most difficult and time consuming part of the software development process. What is Code Review? 1 2 3
  • 3. “No problem can be solved from the same level of consciousness that created it” 3 Albert Einstein
  • 4. Why reviewing code? 4 ● Saving time and money. by finding bugs in early stage. ● Sharing knowledge across the team, no single developer in the critical path. ● Team cohesion. encourage developer to talk each other and bring them closer to each other. ● Coding standard. helps to maintain consistent coding style across the team.
  • 6. 6 Before submitting a pull request COMPILE The code is not broken, should successful compile and build. COVERAGE All code in codebase should be tested, the coverage should not decrease by merging your code. Tests Your tests code should run successfully and pass travis run. READY Your code should be ready for PR, DO NOT assign reviewer to your PR if it’s not completely ready. JIRA Linked to the relevant JIRA item (PR name should start with the JIRA number)
  • 9. ● To make sure that the code is correct and of high quality. ● Review for core logic and architecture aspects. ● Review for adequate test coverage. The reviewer responsible for the code reviewed by him! Reviewer responsibility 9
  • 11. Preparing your code for review 11
  • 12. Communicate with your reviewer Give your reviewers background about your task. Create Pull Request with a reasonable timeframes. Take into consideration the reviewer status, time for reviewer to understand the code and goals, bugs and code refactoring. Give your reviewers context on your change. Ideally, you should speak with them before any non-trivial review or document the changes you’re making inside of the review’s description. Make sure to summarize the change you’re making, why you are making those changes, and link to a ticket or spec to provide any additional context. Since most of us pull request authors have likely been reviewers already, simply put yourself in the shoes of the reviewer and ask, “How could this be easier for me?” 12 Guidelines / Preparing your code review
  • 13. Make smaller pull requests Making smaller pull requests is the best way to speed up your review time. Keep your pull requests small so that you can iterate more quickly and accurately. In general, smaller code changes are also easier to test and verify as stable. When pull request is small, it’s easier for the reviewers to understand the context and reason with the logic. According to review study (see figure) the optimal effectiveness, developers should review fewer than 200-400 lines of code (LOC) at a time. Beyond that, the ability to find defects diminishes. Reviewing 200-400 lines of code over 60-90 minutes, should yield 70-90% defect discovery. Reading beyond 400 lines of code, the ability to find defects diminishes. 13 Guidelines / Preparing your code review
  • 14. Make smaller pull requests 14 Guidelines / Preparing your code review defect density dramatically decreases when the number of lines of inspection goes above 200, and it is almost zero after 400
  • 15. Make your code easy to review- useful description Writing a useful description for your pull request can almost be as effective as making a smaller pull request. Make sure to provide helpful descriptions. The most helpful descriptions guide the reviewer through the code as much as possible, highlighting related files and grouping them into concepts or problems that are being solved. This saves the reviewer a lot of time because they don’t have to read every file to try and group them up and identify related concepts. 15 Guidelines / Preparing your code review
  • 16. Make your code easy to review- comments Code should contain both high-level and in-line comments. High-level comments explain how all the components fit together and how it handles any exceptional cases while in-line comments describe why the code takes its current shape. This will make your code easier to understand for maintainers and reviewers. 16 Guidelines / Preparing your code review
  • 17. Read and annotate your code before you sent it to review Before submitting for review, you should review your own diff for errors. Try to do this through the eyes of someone who has never seen the code before. Look for any decisions that may cause confusion and may need preemptive explanation. If you feel the code is too confusing, you may want to further refine your code before sending it out for review. Catching these issues early will save both you and the reviewers time. You should also annotate code before the review occurs because annotations guide the reviewer through the changes, showing which files to look at first and defending the reason behind each code modification. Annotations should be directed at other reviewers to ease the process and provide more depth in context. As an added benefit, the author will often find additional errors before the review even begins. More bugs found prior to review will yield in lower defect density because fewer bugs exist overall. Another very important issue which is often under-rated is naming. Are packages, classes, methods and variables in your view, optimally named? do you understand all the names? 17 Guidelines / Preparing your code review
  • 18. Use this Checklist ● Am I having difficulty in understanding this code? ● Is there any complexity in the code which could be reduced by refactoring? ● Is the code well organized in a package structure which makes sense? ● Are the class names intuitive and is it obvious what they do? ● Are there any classes which are notably large? ● Are there any particularly long methods? ● Do all the method names seem clear and intuitive? ● Is the code well documented? ● Is the code well tested? ● Are there ways in which this code could be made more efficient? ● Style check your code. 18 Guidelines / Preparing your code review
  • 19. During a code review 19
  • 20. Avoid changes during the code review Major changes in the middle of code review basically resets the entire review process. If you need to make major changes after submitting a review, you may want to ship your existing review and follow-up with additional changes. If you need to make major changes after starting the code review process, make sure to communicate this to the reviewer as early in the process as possible. 20 Guidelines / During a code review
  • 21. Respond to all actionable code review feedback You should understand every piece of feedback from your reviewer and respond to each actionable piece. Even if you don’t implement their feedback, respond to it and explain your reasoning. If there’s something you don’t understand, ask questions inside or outside the code review. 21 Guidelines / During a code review
  • 22. Code reviews are discussions, not dictation You can think of most code review feedback as a suggestion more than an order. It’s fine to disagree with a reviewer’s feedback but you need to explain why and give them an opportunity to respond. 22 Guidelines / During a code review
  • 23. When doing a code review 23
  • 24. Understand the code and requirements Reviewer should: ● Be aware to the task description and requirements. ● Make sure you completely understand the code. ● Evaluate all the architecture tradeoffs. 24 Guidelines / When doing a code review
  • 25. Check code on many aspects 1. Verify the code correctness. * The code is bug-free . * The code does what it was intended to do. * Leak memory, etc. 2. Check code quality . * Make sure the code is maintainable. * Check the code is general as it need to be and well organized. * Is there a better way to accomplish the goal? * Style issues- not consistent with the rest of the codebase. 3. Verify the code is well tested. * All code in codebase should be tested. * Tests are written according Gett guidelines Writing Golang tests * Make sure unit tests are isolated, don’t have unnecessary dependencies and testing the right things. * Confirm adequate test coverage. 4. Make sure the code is safe to deploy. * Ask if the code is forwards/backwards compatible. * Run through a roll-back scenario to check for rollback safety. * Dependencies with other services? 25 Guidelines / When doing a code review
  • 26. Avoid many comments and use github review When you have several comments you should use the review option in github, instead of comment each of them separately, and notify the developer (PR owner) when you finished. This will prevent confusion and providing clearly stated when the review ends. 26 Guidelines / When doing a code review
  • 27. Comments level Another best practice is divide your comments for 3 categories: 1. Critical: Comments that the developer must to accept and change the code: Examples: bug, wrong logic, memory leak etc. 2. Optional: Recommends for the developer for changes, nice to have but not mandatory. 3. Positive Comment: When you find nice piece of code, let the developer know your appreciation 27 Guidelines / When doing a code review