Leveraging ChatGPT for <code/> Review. A Practical Guide.

sandeep vashisth
3 min readJun 5, 2023

Code reviews are an essential part of the software development process, ensuring that code is of high quality, maintainable, and free from bugs before it gets merged. Recently, AI-generated language models like ChatGPT have gained popularity as a valuable tool to assist developers during the code review process. In this blog post, I will show you how to use ChatGPT to review your code and provide helpful suggestions.

Setting up ChatGPT:
Before diving into the code review process, you’ll need to install the ChatGPT extension into Visual Studio Code. If you are using a different code editor or IDE, this can be done through extensions or plugins that are available on their respective marketplaces.

Preparing your code:
To get the most out of ChatGPT’s suggestions, make sure your React code follows best practices, adheres to your team’s coding standards, and includes comments whenever necessary. This preparation step ensures that the AI understands your code better and provides more relevant feedback.

Initiating the code review process:
Once your code is ready for review, you can start using ChatGPT to get suggestions with several options available as follow.

You may ask questions in the ChatGPT panel. To open the ChatGPT panel click on the ChatGPT icon in the sidebar.

You can select some code in the editor, right-click on it and choose one of the following shortcuts from the context menu:

  • Ask ChatGPT: will provide a prompt for you to enter any query
  • ChatGPT: Explain selection: will explain what the selected code does
  • ChatGPT: Refactor selection: will try to refactor the selected code
  • ChatGPT: Find problems: looks for problems/errors in the selected code, fixes and explains them
  • ChatGPT: Optimize selection: tries to optimize the selected code

you may request improvements within the comments of your code. For example:

// ChatGPT: Are there any performance improvements I can make to this function?
function fetchData() {
// Your code implementation...
}

Interpreting ChatGPT’s suggestions:
ChatGPT will analyze your code and provide suggestions in line as comments. Carefully review these suggestions to ensure they align with your project’s goals and requirements. Keep in mind that while ChatGPT is powerful, it might not always provide the best solution. Use your judgment when deciding whether to implement its suggestions. For example:

// Original code
function fetchData() {
// Your code implementation...
}
// ChatGPT's suggestion
// You can use the `useEffect` hook to fetch data when the component mounts and prevent unnecessary re-renders.

Implementing suggestions and reevaluating:
After reviewing ChatGPT’s feedback, implement the suggestions you find valuable. If you have doubts or need further clarification, ask additional questions, and seek guidance from ChatGPT. It may be helpful to engage in a back-and-forth conversation to fine-tune your code.

Collaborating with your team:
In addition to using ChatGPT for code review, remember that collaborating with your peers remains invaluable. Gather feedback from your team members and compare it with ChatGPT’s suggestions. This multi-faceted approach ensures that you receive diverse perspectives that enhance your code quality.

Conclusion:
Integrating ChatGPT into your code review process can save you time, help you spot potential issues, and provide useful suggestions for improvement. While it is a powerful tool, always use your judgment when deciding to accept or reject its recommendations. By combining ChatGPT’s insights with the expertise of your fellow developers, you’ll have an effective and efficient code review process that leads to high-quality, maintainable code.

--

--