☰ 분류

코드 리뷰 전문가 역할 프롬프트

코드 조각, 언어, 중점 영역을 넣으면 버그, 최적화, 코딩 표준, 모범 사례 관점의 피드백을 제공합니다.

분류개발 › 코딩
태그검토분석개발자코드
프롬프트 (영어 본문 · 답은 한국어로 옵니다)
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

어떤 프롬프트인가

주어진 코드에 대한 건설적인 리뷰를 받을 때 쓰는 범용 개발 프롬프트다. 예시를 들어 설명하게 하며, 기본 언어는 JavaScript로 설정되어 있다.

모델 비교

ChatGPT가 정확성과 간결성의 균형이 가장 좋다. Gemini는 상세하지만 장황하고 방어 코드에 결함이 있으며, [C]는 답이 없다.

ChatGPT종합 1위
47/ 50

+ 핵심 오류와 결제 안전성 개선을 간결히 제시했다.

- 통화 반올림 정책을 코드에 명시하지 않았다.

Gemini
41/ 50

+ 버그·비동기·보안 문제를 폭넓고 구체적으로 다뤘다.

- 잘못된 값을 0으로 숨기며 원인을 일부 과단정했다.

기준ChatGPTGemini앞선 모델
지시 준수1010동점
정확성97ChatGPT +29%
구체성109ChatGPT +11%
구성·가독성99동점
분량 적정성96ChatGPT +50%

gpt-5.6-sol가 모델 이름을 가린 채 1~10점으로 채점했습니다 (2026-09-24). 측정값이 아니라 AI 심사 결과입니다.

답 전문 보기

같은 입력을 세 모델에 넣어 받은 답을 그대로 옮겼습니다. 각 CLI(에이전트 하네스)에서 실행했습니다. ChatGPT·Claude 앱이나 웹에서는 답이 다를 수 있습니다.

넣은 입력
[붙여 넣은 자료]
언어: 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 · 에이전트 하네스) · 실행일 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 본문을 제대로 해석하지 못할 수 있습니다.
  • 할인 금액이 상품 합계보다 커지면 음수 합계가 될 수 있습니다.
  • ==와 문자열 비교 대신 ===를 사용하는 것이 안전합니다.
  • 실제 결제 금액이라면 부동소수점 오차를 피하기 위해 원 단위가 아닌 정수 최소화폐단위(예: 센트)로 계산하는 것이 좋습니다.
  • 최종 합계는 클라이언트 값만 신뢰하지 말고 서버에서 장바구니 상품과 쿠폰을 재검증해야 합니다.

같은 분류의 프롬프트

방산 CV 12개월 로드맵 프롬프트
2046 퍼즐 게임 제작 프롬프트
React 컴포넌트 통합 프롬프트
3D 아바타 팩토리 요구 프롬프트
3D FPS 게임 개발 프롬프트