Using GPT to do Code Reviews : A non-tech POV
base Image by rawpixel.com on Freepik

Using GPT to do Code Reviews : A non-tech POV

As GPTs start gaining popularity, there are gradually being used for many non-trivial functions. My daughter was writing some pieces of #python code which I was reading through and thought it would be fun to use GPTs to do code reviews. Of course, there are many such AIs available on the web, some of which are now plugged into IDEs (e.g. GitHub CoPilot) too and help with coding based on prompts. But, what if one didn't have an advanced IDE, what if a business / methodology person, not familiar with AIs like #CodeGuru (from 亚马逊 ), or #Codex ( OpenAI 's coding tool accessed through its API), want to facilitate a code review using a GPT?

The Code Review Process

It took me a few iterations to figure how to optimally use a #gpt to do a code review. I used #chatgpt 3.5, and 4.0 (through #bing ). Here's what works most effectively while using a GPT effectively for doing reviews:

useful process for code reviews through GPT
Simple iterative process to do code reviews using a GPT

  • Describe?/ Explain the code: Provide an overview of the code you want reviewed. Specify the programming language, framework, what the code is required to and other relevant details.
  • Provide the code: Paste the code snippet or the entire file. You might not always be able to provide a URL for the GPT to read; if you are, do so.
  • Ask specific questions: Mention specific concerns that you want the GPT to focus on in the review. These could be code efficiency, readability, leading practices, performance optimizations, potential bugs, or maybe even security vulnerabilities.
  • The Review: The GPT analyzes the code and provides feedback based on the information provided.?
  • Iterative reviews: It appeared that iterations help even more, as one keeps adding to the code. An increasing in size, code block, works well. Though the GPT will do a single code review, it can be used as a coding assistant or say a peer reviewer. It appeared that not only with the AI identify potential issues, suggest improvements but it can also explain complex concepts, and / or offer alternative solutions (through code snippets).?

An Illustrative Review

Following is what I tried, with a short code snippet that I wrote?

Me: Need you to review the following Python code that I just wrote. The following code is required to calculate the factorial of a given number. After reading the code, please answer only in YES or NO, if you understand it.?

No alt text provided for this image
No alt text provided for this image

Me: ok, need you to review the code, and tell me if there are inefficiencies and if you can make the code better.?

No alt text provided for this image
Code improvement suggestions provided by the GPT
No alt text provided for this image
New, better, improved code provided by GPT

Me: Can you make the code a little more efficient?

No alt text provided for this image

Now, the thing is, one needs to do this iteratively through the entire coding process to get optimal results.

However, regardless of the great potential, let us not overestimate a GPT's capabilities. Current AI tech, including language models and coding tools, have limitations and do produce erroneous or hallucinatory outputs. Human involvement and verification is still essential to ensure accuracy, catch potential flaws, and provide the necessary contextual understanding that AI lacks. So, don't just completely rely on the GPT to do your reviews, but a balanced approach that combines the strengths of the GPT with human judgment is essential for achieving reliable and effective results.

--------------------------------------------

What do you think? Write in to?me, or?3nayan, if you want to know more about how to make your organization more effective in today’s fast moving world.

#opinionsmyown | Content copyright 3nayan

Suhas?is co-founder, Partner at?3nayan, a niche Strategy Consulting firm which helps Growth Enablement and Organizational Effectiveness through services in Strategy Re-Energization, Process Engineering, Integrated Process Automation and Digital Transformation.

要查看或添加评论,请登录

社区洞察

其他会员也浏览了