← Back to list

Duet AI — Prompts for Code Review

Authors: Siddharth Singh, Arjun Vijayvargiya & Hasan Khan

Hasan Khan · 2024-04-02 13:25 · 1 claps · 2.2 min read
#google-duet-ai #code-review
Open on Medium ↗
Wiki topics: LIT · Literature & Writing 💻 · Programming

Duet AI — Prompts for Code Review

Authors: Siddharth Singh, Arjun Vijayvargiya & Hasan Khan

This blog is the continuation of the first blog (DUET AI — Prompts for Code Generation). In this blog, we will cover the code review in the following areas.

  1. Bug identification
  2. Performance Optimization
  3. Code Style and Readability
  4. Error Handling

Bug Identification Prompts

Some of the prompts which generate good results for bug identifications are:

  • Are there any potential bugs or logic errors in this code snippet?
  • Could you identify any edge cases where this function might break?
  • Check if this code adheres to best practices for handling user input to prevent security vulnerabilities.

Performance Optimization Prompts

  • Are there ways to make this code more efficient or improve its performance?
  • Suggest alternative algorithms or data structures that could be better suited for this task.
  • Can you identify anything that might create unnecessary bottlenecks in this code?

Code Style and Readability Prompts

  • Does this code follow [project or language] coding conventions and style guidelines?
  • Suggest ways to improve readability with better variable names or comments.
  • Can you refactor this code to make it more modular and easier to understand?

Error Handling Prompts

  • “Check if this code has robust error handling and edge case management.”
  • “Would it be beneficial to add more specific error messages or logging for debugging?”

Security Prompts

  • Does this code have any potential security vulnerabilities?
  • Are there ways to improve input validation or data sanitization?
  • How could this code be made more resilient to attacks like SQL injection or cross-site scripting (XSS)?

Example

Let’s assume you have the following JavaScript function:

JavaScript Code:

function calculateTotal(items) {

let totalCost = 0;

for (item of items) {

totalCost = totalCost + item.price * item.quantity;

}

return totalCost;

}

Here are some prompts you could use with Duet AI:

Bug Identification — Are there any potential errors or issues in the way this ‘calculateTotal’ function works?

Performance Optimization — Can you suggest a more performant way to implement this ‘calculateTotal’ function?

Readability — How could I make this ‘calculateTotal’ function easier to read and maintain?

Security — Does this ‘calculateTotal’ function have any security risks I should be aware of?

Best Practices

Be Specific — Mention the function/code snippet you want reviewed.

Provide Context — Explain the purpose of the code and how it’s used within the larger project.

Focus on Priorities — Prioritize bug identification, security, and performance for critical review areas.

Important Note: Duet AI is a tool to assist with code review, not a replacement for your own understanding and judgment. Always carefully review any suggested fixes and ensure they align with your project’s requirements and best practices.

Demo

Follow this for setting up Duet AI

Repository used: https://github.com/JsIqbal/next-ecommerce

file opened: category-form.tsx

  1. Are there any potential bugs or logic errors in this code

Some good links to read:

https://cloud.google.com/duet-ai/docs/discover/write-prompts

https://www.googlecloudcommunity.com/gc/Community-Blogs/Tips-and-resources-to-maximize-your-productivity-with-Gemini-for/ba-p/702290

Disclaimer: The authors of the blog work for different organizations and above are their observations and learning while working on a project. It doesn’t reflect their employer’s view.


메타데이터
post_id
4979c4e1c7fb
slug
duet-ai-prompts-for-code-review-4979c4e1c7fb
url
https://medium.com/@hasanasgharkhan/duet-ai-prompts-for-code-review-4979c4e1c7fb
canonical_url
https://medium.com/@hasanasgharkhan/duet-ai-prompts-for-code-review-4979c4e1c7fb
author_url
https://medium.com/@hasanasgharkhan
status
ok
fetched_at
2026-07-24 12:42:38