How to give Code Review Feedback?

Code review helps you to improve the quality and maintainability of your code. However, this process is challenging for both engineering managers and developers. While managers need to perform thorough reviews to ensure code quality, developers are usually overwhelmed when receiving feedback.

Code review is a critical part of software development and plays a key role in fostering collaboration among team members. The review begins when a developer creates a pull request or changelist, initiating the feedback process.

Engineering managers need to be courteous and respectful while offering constructive feedback to their developers. They must be clear with their feedback so that developers can understand your feedback in the right way and not take it negatively.

In this blog post, let’s explore the ways to provide code review feedback to developers:

What is Code Review?

Also known as peer review, code review is a key practice within quality assurance. It is a systematic examination of source code by one or more individuals to improve its quality, identify issues, and ensure that it aligns with established coding standards and best practices. Code review comments play a crucial role in this process by providing actionable and constructive feedback, helping developers understand what needs improvement and fostering a positive collaboration environment.

Code reviews are often facilitated by source control systems, which help manage code changes and streamline the review process.

Why Code Reviews are Important?

Catches Issues Early

Code reviews allow engineering managers and developers to detect issues and bugs (finding bugs early is a key benefit of code reviews) in the early stages. This process also helps identify wrong implementations or logic before they reach production. So that the problems can be fixed before the end-users see them. Besides this, It allows developers to work with fresh knowledge, or else they may struggle to remember code, solutions, and reasoning.

Supports Knowledge Sharing

Reviewing code regularly allows developers to learn more reliable techniques and best practices. It helps in gaining valuable insights into diverse coding styles and problem-solving approaches. Code review also allows engineering managers to mentor junior developers and support junior team members through constructive feedback, fostering a culture of continuous learning and growth. Senior developers play a crucial role in sharing advanced knowledge and best practices during code reviews, ensuring the team benefits from their experience.

Increases Code Readability

Regular code reviews ensure the entire team adheres to consistent coding standards and best practices, such as following naming conventions and clear variable naming. This makes it easier for developers to understand and contribute to the codebase. Hence, they can write more readable and maintainable code over time. Besides this, it provides opportunities for refactoring.

Minimizes Technical Debt

Optimizing code through the code review process eliminates a significant amount of technical debt. It also detects code smells which are early signs of potential technical debt. Code reviews analyze the code and catch bugs to reduce the need for extensive rework later.

While not all technical debt is inherently a bad thing, code reviews help ensure it is managed appropriately.

Crafting Better Code Reviews. Adapted and reworked from a talk… | by  Vaidehi Joshi | Medium

10 Ways to Provide Code Review Feedback

Ask Questions During the Code Review Process

Always ask questions rather than demanding changes. It not only opens up a dialogue and encourages discussion but also lets them think about input without being defensive. This also ensures that both parties can decide on the right course of action and know each other’s perspective. When asking questions, developers can explain their thought process and rationale behind the code and provide more context for their decisions. Framing a comment as a question during code review encourages open discussion and constructive feedback, making the commenting process more collaborative and effective. This also fosters a culture of collaboration and highlights that nobody is always right. Framing feedback as requests rather than commands promotes a sense of autonomy for the code author.

Example

Instead of saying ‘Change the variable name', ask ‘I see you named this variable ‘Temp'. What about calling this variable ‘UserID'?

Avoid Using Condescending Words

It is seen that written constructive feedback is usually taken negatively. Since the individual cannot see the body language, facial expressions, or tone of the other person. Words like just, easy, and obvious may seem belittling to the developers. This not only diminishes confidence but also introduces ambiguity within the team.

Make sure that you provide feedback in clear and complete language. And most importantly, Be polite! Feedback should never be framed as a personal attack. A note in a code review should be constructive, specific, and never vague or dismissive, focusing on principle-based suggestions rather than commands.

This will help developers grow and work efficiently. Hence, enhancing overall code quality.

Example

Don't say ‘This fix is way too easy'. Instead, use this ‘I see a straightforward implementation here. Can you walk me through your decision-making process?'

Focus on the Code, Not the Developer

Address the code directly rather than the developer. Focus feedback on the code itself, not the code author. Discuss what can be improved in the code, not the developer’s skills or characters. Blaming them will lead to judgments, rejections, and defensiveness. They would avoid taking feedback positively. Focusing on the code and its logic, rather than the individual, leads to more objective and productive reviews. Assuming miscommunication over malice during code reviews can help maintain a positive atmosphere.

Hence, ensure an objective evaluation of the code. Guide code authors by offering specific suggestions for improvement and clarity. Make this process a team sport that focuses on the code and its improvement, and focus only on facts.

This will not affect any interpersonal relationships within the team and developers will take feedback seriously.

Example

Instead of saying ‘You haven't optimized the code efficiently', You can say ‘This code hasn't been optimized properly'.

Explain the ‘Why' Behind the Feedback

Instead of just telling what improvements to be made to pull requests or code, explain the reason behind the change. Let developers know about the thought process and reasoning so that they look from the other’s perspective. Add a brief explanation along with the change mentioned.

Never assume that developers understand the ‘Why’ behind the change. Always clarify the reason so that they know where it is coming from. Explaining the underlying logic behind code changes helps developers understand and apply feedback more effectively. Clear explanations help ensure the code is understandable for future changes and for future readers who may need to review or maintain the code.

This will help developers improve their skills and knowledge, enhancing code quality.

Example

Don't say ‘Update the variable names'. Instead, say this ‘Try adding descriptive variable names to enhance code readability and make it easy for other developers to collaborate and maintain the codebase.'

Use ‘I' Statements

Clarify to developers that it is not a universal statement or generalization. Rather, it’s an observation or one perspective as per the code written.

Hence, use ‘I’ while writing constructive feedback. It not only fosters an open and receptive environment for discussing code changes and improvements but also makes it easier for both sides to look for solutions.

This makes developers less defensive about their work and more open to pair programming and learning opportunities. Using ‘I’ statements is a helpful and good practice for effective communication. Making your point with 'I' statements helps avoid misunderstandings and defensiveness.

Example

‘The code is hard to follow' should be changed to ‘I am finding this flow of code a bit challenging to follow.'

Suggest Solutions

Always suggest solutions and guidance on how they can improve. Use your expertise to suggest improvements and offer at least one suggestion for each major issue you identify. It could be a framework, method, or API. It doesn’t mean giving a complete solution but sharing an improvement strategy. This will save developers time in implementing these suggestions and address issues (which they might have overlooked). Also, they will be able to learn new techniques, best practices, and coding standards to improve their coding skills.

Use examples as well so they understand the solution practically. For instance, you can recommend refactoring code into reusable functions, improving the implementation of a specific function for better maintainability, or using a list comprehension in Python to make the code more concise and readable where appropriate.

Example

If the loop structure is inefficient, suggest a solution like ‘Consider using a 'for-each' loop instead of a 'for' loop for better readability and concise code.'

Share Learning Resources

Apart from solutions, share learning resources with them. It could be related to the areas where developers need improvement, new industry trends, or code review best practices. It will help them stay updated with the current trends and improve their understanding of specific technologies and frameworks. Resources such as relevant documentation, tutorials, and online courses work wonders. Sharing resources on JavaScript best practices can help developers stay updated with modern web development trends. You can also share insightful articles or a comprehensive article on best practices. Work with your team to build these automated checks directly into the code review workflow.

This will help developers take ownership of their learning and foster a sense of autonomy.

Example

Instead of simply pointing out the developer's blindspot, for example - Not familiar with the new framework's syntax. Write this - ‘I noticed some challenges with the syntax of the new framework. I recommend checking this document ‘Framework Documentation.' as it provides clear examples and explanations.'

Keep Code Reviews Small

Review code frequently as it reduces the need to make the process lengthy. Long code reviews would be overwhelming and confusing for developers since they need to make a lot of changes and improvements altogether. Even after doing it frequently, the code reviews take hours, break it down into small parts. Reviewing fewer lines of code at a time makes the process more manageable and allows reviewers to focus on specific lines for targeted feedback and discussion. Attaching feedback directly to a particular line clarifies the context of the comment and makes the review more actionable.

Smaller code reviews allow developers to understand the reason behind the constructive feedback. Hence, they can make changes to the code without any dilemma or misunderstanding.

Example

Suppose a developer has submitted a large pull request that considers various features and changes.

Instead of sharing feedback all at once, say this ‘Let's first focus on the changes related to the new feature implementation. Once done, we can move on to reviewing the improvements in the existing code.'

Appreciate your Developers

Effective code reviews take place when both positive and constructive feedback is included. Developers may make a few mistakes here and there. But, this doesn’t come from a bad place. They are improving, growing, and giving their best.

Hence, pat their backs on the things they have done correctly. Positive feedback creates a culture of recognition and gratitude which improves collaboration and communication.

This also lets development teams to continue put efforts and strive for excellence. Appreciation should be extended to all team members, as recognizing the contributions of everyone fosters a stronger team dynamic. Both the reviewer and the recipient benefit from positive feedback, reinforcing a collaborative and supportive environment. Recognizing valuable feedback encourages continuous improvement and motivates team members to keep enhancing their skills.

Example

When recognizing their efforts, say this ‘Nice job on the new feature. Your attention to detail and writing readable code is commendable.' Praise specific aspects of the code enhances morale, such as acknowledging good use of dependency injection or clarity in structure.

Use Automated Code Review Tools

Use code review tools to help in assessing the quality of code. These tools can help in spotting bugs and vulnerabilities, detecting code smells, syntax errors, security vulnerabilities, and many more. Automated checks and continuous integration pipelines can automatically correct style issues, enforce naming conventions, and ensure high quality code. These tools can also highlight areas that need code comments, support inline comments, and make commenting more efficient and consistent. Automated tools may also politely recommend placing related code, such as CSS or scripts, into a separate file to improve maintainability. It also gives visibility into changes, hence, making the feedback more focused and contextually relevant. Automated checks run in the background whenever a pull request is opened.

These tools also ensure that the code adheres to the coding standards and best practices.

Typo: Automated Code Review Tool

Typo’s automated code review tool combines the power of hybrid Static Application Security Testing (SAST) and advanced AI-driven analysis to deliver comprehensive code reviews. Supporting tall top programming languages, it seamlessly integrates with any major programming language and leverages their unique language features. This innovative approach not only detects potential security vulnerabilities and code quality issues early but also provides intelligent suggestions to improve code quality and maintainability.

By automating routine checks and offering valuable feedback, Typo’s tool reduces the time spent on manual reviews, allowing developers to focus on complex logic and creative problem-solving. Its deep contextual understanding ensures accurate issue detection and precise, actionable recommendations, making the entire code review process faster, smoother, and more effective.

Key Features:

  • Hybrid SAST and AI-powered code analysis for enhanced security and quality
  • Supports all top languages
  • Context-aware issue detection with intelligent, actionable feedback
  • Automated debugging assistance with detailed explanations
  • Standardizes code style and enforces best practices to improve maintainability
  • Helps identify and reduce potential security risks early in the development lifecycle
  • Provides AI-powered pull request (PR) summaries to give reviewers clear context, enhancing the code review process

Conclusion

The code review process might be time-consuming, but, it is rewarding too. Code reviews are a fundamental part of software engineering and contribute to a virtuous cycle of continuous improvement. It helps in knowing whether the code needs refactoring, has bugs or errors, or anything else that could hamper its performance.

Follow the 10 tips mentioned above to encourage collaboration, open communication, and knowledge sharing among developers. The key points discussed include best practices for effective reviews, and leaving actionable notes during code reviews can help guide future improvements and clarify feedback for your team.

Happy reviewing!