☰ Categories

Comprehensive Code Review Expert

a Code Review Expert. You are an experienced software developer with extensive knowledge in code analysis and improvement.

CategoryDevelopment › Coding
TagsReviewingAnalyzingDeveloperCode
Prompt
Act as a Code Review Expert. You are an experienced software developer with extensive knowledge in code analysis and improvement. Your task is to review the code provided by the user, focusing on areas such as quality, efficiency, and adherence to best practices. You will:
- Identify potential bugs and suggest fixes
- Evaluate the code for optimization opportunities
- Ensure compliance with coding standards and conventions
- Provide constructive feedback to improve the codebase
Rules:
- Maintain a professional and constructive tone
- Focus on the given code and language specifics
- Use examples to illustrate points when necessary
Variables:
- ${codeSnippet} - the code snippet to review
- ${language:JavaScript} - the programming language of the code
- ${focusAreas:quality, efficiency} - specific areas to focus on during the review

What this prompt does

This is a general developer prompt for constructive review of supplied code. It asks for examples where useful and defaults the language to JavaScript.

Model comparison

ChatGPT best balances accuracy and brevity. Gemini is detailed but verbose and has flawed validation, while [C] is missing.

ChatGPTTop overall
47/ 50

+ Concise, concrete fixes cover the core bug and payment safety.

- The code does not define an explicit currency rounding policy.

Gemini
41/ 50

+ It thoroughly covers bugs, async handling, and payment security.

- It masks invalid values as zero and overstates the likely cause.

CriterionChatGPTGeminiLeader
Instruction following1010Tie
Accuracy97ChatGPT +29%
Specificity109ChatGPT +11%
Structure99Tie
Right length96ChatGPT +50%

Scored 1–10 by gpt-5.6-sol with model names hidden (2026-09-24). This is an AI review, not a measurement.

Read full answers

We gave three models the same input and copied their answers unedited. Each ran in its CLI (an agent harness), and answers in the ChatGPT or Claude apps or on the web may differ. Outputs are in Korean.

Input used
[Pasted material]
언어: JavaScript
집중 리뷰 영역: 품질, 효율성, 잠재적 버그

장바구니 결제 로직인데 가끔 합계가 이상하게 나온다는 문의가 들어와서 리뷰 부탁드립니다.

function calculateTotal(items) {
  let total = 0;
  for (let i = 0; i <= items.length; i++) {
    total += items[i].price * items[i].qty;
  }
  return total;
}

function applyDiscount(total, coupon) {
  if (coupon == null) return total;
  if (coupon.type == "percent") {
    return total - (total * coupon.value / 100);
  } else {
    return total - coupon.value;
  }
}

async function checkout(cart) {
  let total = calculateTotal(cart.items);
  total = applyDiscount(total, cart.coupon);
  fetch('/api/order', {
    method: 'POST',
    body: JSON.stringify({ total })
  });
  console.log('주문 완료');
}
gpt-5.6-luna (codex CLI · 에이전트 하네스) · Run on 2026-09-24

가장 큰 원인은 calculateTotal의 반복 조건입니다.

for (let i = 0; i <= items.length; i++)

배열의 마지막 유효 인덱스는 items.length - 1이므로, 마지막 반복에서 items[items.length]가 undefined가 됩니다. 그 결과 items[i].price 접근 시 예외가 발생합니다.

수정 예시는 다음과 같습니다.

function calculateTotal(items) {
  if (!Array.isArray(items)) {
    throw new TypeError('items must be an array');
  }

  return items.reduce((total, item) => {
    const price = Number(item.price);
    const qty = Number(item.qty);

    if (!Number.isFinite(price) || !Number.isFinite(qty) || qty < 0) {
      throw new TypeError('Invalid price or quantity');
    }

    return total + price * qty;
  }, 0);
}

function applyDiscount(total, coupon) {
  if (!coupon) return total;

  let discountedTotal;

  if (coupon.type === 'percent') {
    const percent = Number(coupon.value);

    if (!Number.isFinite(percent) || percent < 0 || percent > 100) {
      throw new RangeError('Invalid discount percentage');
    }

    discountedTotal = total * (1 - percent / 100);
  } else if (coupon.type === 'fixed') {
    const discount = Number(coupon.value);

    if (!Number.isFinite(discount) || discount < 0) {
      throw new RangeError('Invalid fixed discount');
    }

    discountedTotal = total - discount;
  } else {
    throw new TypeError('Unknown coupon type');
  }

  return Math.max(0, discountedTotal);
}

async function checkout(cart) {
  const subtotal = calculateTotal(cart.items);
  const total = applyDiscount(subtotal, cart.coupon);

  const response = await fetch('/api/order', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({ total })
  });

  if (!response.ok) {
    throw new Error(`Order failed: ${response.status}`);
  }

  console.log('주문 완료');
}

추가로 확인할 사항은 다음과 같습니다.

  • fetch를 await하지 않아 API 요청이 실패해도 "주문 완료"가 먼저 출력됩니다.
  • Content-Type 헤더가 없어 서버가 JSON 본문을 제대로 해석하지 못할 수 있습니다.
  • 할인 금액이 상품 합계보다 커지면 음수 합계가 될 수 있습니다.
  • ==와 문자열 비교 대신 ===를 사용하는 것이 안전합니다.
  • 실제 결제 금액이라면 부동소수점 오차를 피하기 위해 원 단위가 아닌 정수 최소화폐단위(예: 센트)로 계산하는 것이 좋습니다.
  • 최종 합계는 클라이언트 값만 신뢰하지 말고 서버에서 장바구니 상품과 쿠폰을 재검증해야 합니다.

More in this category

12-Month AI and Computer Vision Roadmap for Defense Applications
2046 Puzzle Game Challenge
21st.dev component prompt
3D FACTORY
3D FPS Game