HomeNews and blogs hub

Code Review: an opportunity to upskill

Bookmark this page Bookmarked

Code Review: an opportunity to upskill

Author(s)

Raniere Silva

Posted on 24 May 2022

Estimated read time: 3 min
Sections in this article
Share on blog/article:
Twitter LinkedIn

Code Review: an opportunity to upskill

Posted by s.aragon on 24 May 2022 - 11:00am

By Raniere Silva.

Code review is a software development practice that pre-dates the GitHub era of collaboration (after 2008) when Bugzilla was king and review was a sequence of plain text messages between developers instead of the discussion threads anchored in lines of the diff that GitHub and GitLab provide today. Code review contributes to improving the robustness of the application and is an opportunity to teach collaborators how to improve the quality of source code.

Quality of source code is subjective but we can agree on a few baseline rules. For example, a source code that has variables and functions with clear and concise names is better than one with random single letter names. Most of the baseline rules can be enforced using a code analysis tool (or linter) and included into the continuous integration workflow.

Meanwhile, the quality of the logic structure implemented in the source code is very subjective. For example, consider the task of mapping a set of strings in a table from a CSV file as described below:

  • flower → 🌸
  • party popper → 🎉
  • heart → ❤

To accomplish the task, we can employ a for-loop like

for cell in table:     replace_string(cell)

 

and the replace_string() function can be

Implementation A Implementation B
def replace_string(cell): if cell == "flower": return "🌸" elif cell == "party popper": return "🎉" elif cell == "heart": return "❤" else: return cell   def replace_string(cell): my_map = { "flower": "🌸", "party popper": "🎉", "heart": "❤", } def replace_string(cell): if cell in my_map: return my_map[cell] else: return cell

 

Some might prefer "Implementation A" because it has a linear structure to read and others might prefer "Implementation B" because it abstracts the map task and future changes only involve the my_map variable.

Screenshot showing reviewers tab on github

In the scenario that developer A submits a pull request with "Implementation A" and the pull request will be reviewed by developer B who prefers "Implementation B", the code review is a learning opportunity for both developers as they will share their quality of source code preferences and reach an agreement for the project.

GitHub, GitLab and Bitbucket/Jira offer a friendly web interface to conduct code reviews and I leave you with five tips to make code review part of the culture of your team:

  1. Ask review of the pull/merge request using the "Reviewers" field in your contribution.
  2. Add a block of time in the team calendar to code review and make it a recurrent event like the team meetings.
  3. Have all hands on board, from interns to team leaders, during the code review team event.
  4. Write the review as an ally by showing empathy. If a senior developer is reviewing the contribution of a junior one, the senior developer can offer to work together to address the points raised during the review.
  5. Invite all participants to share one thing they learnt during the review.  

 

Share on blog/article:
Twitter LinkedIn