• January 2018 (2)
  • December 2017 (1)
  • November 2017 (2)
  • October 2017 (3)
  • September 2017 (4)
  • August 2017 (3)
  • July 2017 (3)
  • June 2017 (3)
  • May 2017 (1)
  • February 2015 (2)
  • January 2015 (1)
  • December 2014 (3)
  • February 2014 (2)
Tags View All Blogs
Scrum.NetMicrosoftVisual StudioVC++C#JavaTestingQuality AssuranceUX DesignSPAAngularKnockoutBackboneUnderscoreDatabaseMySQLBlockchainHyperledgerChaincodeEnterprise MobilityUIIonicCordovaHybrid AppCode ReviewTypescriptAndroidIOTReactICOVenture CapitalArtificial IntelligenceKotlinIoTFuchsia OSVirtual RealityVOIPCrowdfunding Testing

Importance of Code Reviews

Culture of maintaining good quality needs to be incorporated in everyone's blood. Everyone appreciates a good product, whether in terms of hardware or software.

Who is responsible for quality?

Quality Assurance (QA) team, it’s right in their name.
We all know this is not the right answer. Everyone has their role to play in ensuring quality.

Quality standards must be baked in from the beginning. QA cannot add quality to the code at the end.

How one can maintain a good quality product?

A lot of suggestions like following coding standards, latest design patterns, performing code analysis, unit testing, integration testing, etc. will come.

Code reviews often do not get recognized as part of development activity in agile methodology, people might skip this activity in case of tight deadlines. I think sooner or later it pays to write good quality code.

How to ensure that you are writing good code?

First of all, it’s the developer's job. Everyone can write code. Google, StackOverflow, CodeProject, Github, etc. have been really helpful. After writing, code review starts with developer testing their own code. They are responsible for the code they write. It is most easily done when the code is fresh in mind. Sometimes, change might seem trivial, but it should be tested before submitting.

If find yourself asking “do I really need to test this change”?
A senior developer in my company used to say: Every path. Every line. Every time

How you can test your code?

There are different types of developer testing which might apply to some code and not to others.

Desk Checking: Before submitting your code, walk through your code and make sure your code changes makes sense. Try to put yourself in code reviewer's shoes, see it from his perspective. Make sure all the standard patterns and coding guidelines are followed.

Manual Testing: You should be using a debugger to step through all of your code changes, making sure to exercise all logical paths. The next important thing is to make sure unit tests are created in your code. It will also help to debug through all your code changes. Also, make sure your code is working in an integrated environment.

Automated Testing: This type of testing could ensure that your changes do not break any existing code. It will also help in reducing the turnaround time to successfully complete your tasks. Manually testing will definitely take too long, as compare to automated testing. Common types of automated testing:

  • Unit testing: For testing individual unit of code and making sure all the unit test cases are getting executed successfully.
  • Integration testing: For testing components or units of code to verify interactions between them.

Build Testing: In order to perform above types of testing, your code must build. You should always build in clean environment.

Apart from developer testing, Code Reviews are the best way to ensure that all code is of high quality is to perform code reviews. There are few types of code review practices that we can use depending on the situation:

Self Driven Code Reviews:

  • What: Any and all the changes
  • When: Before submitting your code for peer or group review.
  • Who: You (Code author)
  • Why: Avoid errors and your co-workers time.
  • How: Perform Desk checking. Run tools like style cop, fxcop code analysis etc,

Peer Code Reviews:

  • What: Interim check-ins, Defect fixes or any other code change that does fall under group code review.
  • When: Same day is always preferable.
  • Who: Any developer working in same project. Ideally, should have knowledge in the area.
  • Why: Get a second set of eyes on the changes. A reviewer with neutral perspective can notice things that author have missed.
  • How:
    • Examine the difference for all changed files and look at new files. You can use tools like beyond compare, win merge or Visual Studio TFS also provides this feature.
    • Resynchronize the changes to make sure all coding guidelines are followed, code compiles, installers are getting build or websites are getting published.
    • Developer and Reviewer are responsible to ensure that all new code and modified code
      1. is efficient and correct
      2. is maintainable, robust and testable
      3. has appropriate unit test cases
      4. has proper error handling and logging

Group Code Reviews:

  • What:
    • New feature, medium or large chunk of code is changed for feature
    • Changes to any high risk/complex/critical sections of code
    • Creating or changing major interfaces
    • Non-trivial DB or UI changes
  • When: If you following agile, you can plan it at end of sprint or completion of a milestone.
  • Who: You (author), one or two developers, One senior developer or technical lead.
  • Why:
    • Increase Accountability
    • Spread best practices by examples
    • Increase awareness about code base and product
    • Leverage diverse experience and opinions
  • How:
    • Code Author should take ownership and schedule a meeting.
    • Ideally, all participants should review the code on their own before meeting and take notes.
    • Hurry, best to get agreement up front.
    • One person should take notes of any modifications.

What to avoid while performing code reviews:

  1. Review more than 400 lines of code in one go.
  2. Process takes more than 60 minutes.
  3. Blame - game.
  4. Performing reviews without checklist.

Tools that could help in performing code reviews:

  1. Using Source version control system (Git, SVN, TFS, Mercurial)
  2. Win merge’ or ‘Beyond Compare’ for comparisons.
  3. Crucible
  4. Smart Bear Collaborator
  5. Bit Bucket

Benefits of Code Reviews:

  1. Everyone learns and get better.
  2. It limits risk.
  3. It dramatically improves code quality.
  4. Increase knowledge and awareness about the project
  5. Reduces cost of development and maintaining a product or website.