Blog - Trusted Team Extension Partner For Europe & USA

Code Review | Criticism is a Blessing in Software Engineering - Best Software Development Team Extension Partner for Nordics

Written by Iffat Zabin | 11/09/2024

Criticism in software development has a controversial reputation.

Many people see it as negativity, finger-pointing and fault-finding. For code reviews, however, criticism is not only helpful but essential. Embracing constructive criticism can lead to better code quality, improved teamwork, and personal growth as a developer.

That’s why criticism is indeed a blessing in software engineering, especially for code reviews.

 

Understanding Code Reviews

Before we jump into the benefits of criticism, let’s first understand what a code review is. In simple terms, a code review is a process where other developers examine your code to ensure it meets certain standards. This process can catch bugs, improve code readability, and ensure adherence to best practices. The key players in a code review are the author (the person who wrote the code), the reviewer (the person examining the code), and sometimes stakeholders who have a vested interest in the project’s success.

 

The Constructive Nature of Criticism

When you receive constructive criticism, then you know that there is some room for improvement. When it comes to constructive criticism, it is particular and actionable about the work, not the person. However, negative criticism is usually unspecific, unhelpful, and may seem directed against an individual. In code reviews, however, the aim is always to be constructive in criticizing a programmer’s work.

Here’s why:

Improved Code Quality
Constructive criticism helps catch errors and suggests improvements that can make your code more efficient, readable, and maintainable.

Enhanced Collaboration and Team Dynamics
By giving and receiving feedback, team members learn to communicate better, trust each other, and work more effectively as a unit.

Personal and Professional Growth
Constructive criticism helps you see your blind spots, learn new techniques, and grow as a developer.

 

Code Reviews as a Learning Tool

One of the greatest benefits of code reviews is the opportunity to learn. As your code gets reviewed, you get insights into various coding styles and techniques. You will even gain knowledge from feedback given by different people who might be more experienced or with different perspectives. This exposure to diverse approaches can considerably develop your skills.

For example, let’s assume that you have written a piece of code that works fine although somewhat convoluted. During a code review, one of your colleagues may recommend using a simpler way that gives the same result but faster for accomplishing the same goal as yours did in the first instance. This improves not only your codes but also teaches other better ways in which you can apply them in future times.

 

Mentoring Through Code Review 

Mentoring using code review is a powerful approach to developing software engineers, combining the structured feedback of code reviews with the personalized guidance of mentoring.

In this method, mentors review the code written by their mentees, providing detailed, constructive feedback on various aspects such as code quality, adherence to best practices, efficiency, and security. This feedback is not merely a list of corrections but an educational tool, where the mentor explains the reasoning behind each suggestion, shares alternative approaches, and highlights potential pitfalls. 

Through these reviews, mentees gain practical insights and a deeper understanding of coding principles that are often not covered in formal education. Additionally, mentors can identify specific areas where mentees need further development and tailor their guidance accordingly, offering targeted resources, exercises, and additional sessions to address these gaps. 

This hands-on, iterative process not only enhances the mentee’s technical skills but also fosters a culture of continuous learning and collaboration within the team. 

Ultimately, mentoring through code reviews bridges the gap between theoretical knowledge and practical application, accelerating the professional growth of mentees and strengthening the overall quality of the codebase.

 

Common Misconceptions About Criticism in Code Reviews

Despite the benefits, many developers have misconceptions about criticism in code reviews:

1. Criticism as a Personal Attack 

Some developers feel that any criticism of their code is a personal attack. This mindset can create defensiveness and prevent growth. It’s important to realize that feedback during code reviews is about the code, not the coder. The main goal is to spot potential issues, improve code quality, and ensure best practices are followed.

For instance, if a colleague suggests using a more efficient algorithm or points out a security flaw, it’s not a judgment of your skills but an opportunity to make the code better. Separating your personal identity from the code you write is crucial. Remember, the review process aims to collaborate and build better software together.

Creating a culture of positive and constructive feedback helps. Reviewers should focus on the code and offer suggestions respectfully and helpfully. As a developer receiving feedback, view it as a learning opportunity, not as a critique of your abilities.

2. Fear of Negative Feedback  

Fear of negative feedback can discourage developers from seeking reviews. This fear might come from past experiences, lack of confidence, or the belief that criticism equals failure. However, understanding that feedback’s goal is improvement can help mitigate this fear.

Negative feedback should be seen as a step toward better code quality and personal growth. For example, if a reviewer points out a potential bug or performance issue in a function, addressing this feedback can lead to a more robust and efficient codebase. Constructive criticism helps identify blind spots and areas for improvement that the original author might have missed.

To overcome this fear, developers should embrace a growth mindset. Recognize that feedback, even if negative, is a valuable tool for learning and development. Encourage open communication and create a supportive environment where constructive criticism is welcomed and viewed as a normal part of the development process.

3. The Myth That Only Junior Developers Need Code Reviews 

A common misconception is that only junior developers need code reviews. This myth can lead to complacency among more experienced developers, who might believe they have outgrown the need for feedback. However, code reviews are beneficial for everyone, regardless of experience level. Even seasoned developers can miss things or benefit from a fresh perspective.

Experienced developers are not immune to mistakes. Complex codebases, evolving best practices, and the ever-changing landscape of technology mean that continuous learning and improvement are necessary. Code reviews provide an opportunity for knowledge sharing, catching subtle bugs, and ensuring that the code adheres to the latest standards and practices.

For example, a senior developer might write an intricate algorithm that works perfectly but is not as readable or maintainable as it could be. A code review can offer suggestions for simplification or improvement that make the code easier for others to understand and work with in the future. By embracing code reviews, even experienced developers can refine their skills and contribute to a higher overall code quality.


Strategies for Giving Constructive Criticism

Giving constructive criticism is an art. Here are some strategies to do it effectively :

Be Specific and Objective
Instead of saying “This code is bad,” explain what specifically can be improved and why. For example, “This loop can be optimized to reduce runtime by doing X.”

Focus on the Code, Not the Coder
Make it clear that your feedback is about the code, not the person. Use language like “The function” instead of “You.”

Use Positive Language and Provide Actionable Suggestions
Frame your feedback positively and offer clear, actionable suggestions. For example, “Great job on X! To make it even better, consider doing Y.”

Encourage a Two-Way Dialogue
Invite the author to ask questions and discuss the feedback. This can lead to a better understanding and more effective improvements.


Strategies for Receiving Criticism Gracefully

Getting criticized may be tough but necessary for development. Here are suggestions on how to do it gracefully:

Keep an Open Mind
Take feedback as an opportunity for learning and growth if you want your code to get better.

View Feedback as an Opportunity for Improvement
Instead of seeing criticism as a negative, see it as an opportunity to learn and grow.

Ask for Clarification When Needed
If you don’t understand the feedback, ask for clarification. This shows that you’re engaged and eager to improve.

Separate Personal Identity from the Code Written
Your code is not a reflection of your worth as a person. It’s just code, and it can always be improved.

 

Best practice for GitHub Pull Request (PR) Reviews

Pull Request (PR) reviews on GitHub are an essential part of maintaining high code quality and fostering effective collaboration within a development team.

Here’s a detailed look at these best practices:

Select Specific Lines to Comment On

When reviewing a PR, it’s crucial to highlight specific lines or sections of the code that need attention. This makes it clear exactly what you’re referring to, avoiding any confusion.

Example:

  1. Scroll through the changes to find the line(s) you want to comment on.
  2. Hover over the line number where you want to add a comment. You’ll see a blue “+” icon appear on the left side of the line number.
  3. Click the blue “+” icon to open the comment box.
  4. In the comment box that appears, type your feedback. Be specific and clear in your comments, providing context and suggestions as needed.
  5. If you need to comment on multiple lines, you can select a range:
  6. Click and drag to highlight multiple lines. After selecting the range, click the “+” icon that appears to the left of the highlighted lines.
  7. Once you’ve typed your comment, click the “Start a review” button to begin a review session, or click “Add single comment” to add the comment without starting a review.
  8. Once you’ve finished adding comments, click the “Review changes” button at the top right of the “Files changed” tab.

Engage in Constructive Dialogue

Encourage discussions by asking questions or seeking clarification on implementation choices. This fosters a deeper understanding and aligns the team on technical decisions.

Response to Replies 

Stay engaged in the review process by responding promptly to comments from the author. This ensures smooth progress and resolves any outstanding questions or concerns.

 

The Role of a Healthy Team Culture

A healthy team culture is crucial for effective code reviews. Here’s how to build one:

Promote a Culture of Continuous Learning and Improvement
Encourage team members to see code reviews as opportunities for learning and growth.

Build Trust Among Team Members
Trust is essential for giving and receiving feedback. Foster an environment where team members feel safe to share their thoughts and suggestions.

Encourage Regular and Structured Code Reviews
Make code reviews a regular part of your workflow. This helps normalize the process and ensures that everyone gets feedback.

 

Personal Experience

There was this one time I submitted a piece of code that I was quite proud of. During the review, I was pointed out by my colleague who said that there might be possible security vulnerabilities that had escaped my attention completely. This enabled me to fix the problem before it could become an issue due to the feedback given to me by him. This experience taught me two things; one was about the importance of code reviews and secondly how valuable constructive criticism is. Constructive criticism, when given respectfully and thoughtfully, is a powerful tool for growth.

 

Conclusion

To summarize, it is important to note that criticism in code reviews should not be feared or evaded. It is a blessing that can lead to superior code, better teams, and personal growth.

Once we embrace constructive criticism, we will be able to improve our skills, learn new tricks and deliver high-quality software. Therefore, the next time you receive feedback on your code, take it as an opportunity for learning and growing.

While giving your feedback, think about helping your colleagues rather than criticizing them for their mistakes. By working together we can create a culture of continuous improvement and excellence in software engineering.

By following these guidelines and embracing the value of constructive criticism, we can all become better developers and contribute to the success of our teams and projects.