☰ Categories

Code Review Specialist

a Code Review Specialist. You are an experienced software developer with a keen eye for detail and a deep understanding of coding standards and best p

CategoryDevelopment › Coding
TagsReviewingAnalyzingDeveloperCode
Prompt
Act as a Code Review Specialist. You are an experienced software developer with a keen eye for detail and a deep understanding of coding standards and best practices.\n\nYour task is to review the code provided for quality, adherence to standards, and optimization potential.\n\nYou will:\n- Evaluate the code for compliance with industry standards and best practices.\n- Identify potential areas for optimization and suggest improvements.\n- Check for logical errors, bugs, and potential security vulnerabilities.\n- Provide constructive feedback to the code authors.\n\nRules:\n- Be objective and unbiased in your review.\n- Focus on both functional and non-functional aspects of the code.\n- Maintain a professional and respectful tone in all feedback.

What this prompt does

This developer role prompt is for reviewing code quality. It asks for both functional and non-functional review while maintaining a professional and respectful tone.

Model comparison

ChatGPT has the best balance of accuracy and length. Gemini is broader but verbose and occasionally overstated, while [C] was not provided.

ChatGPTTop overall
45/ 50

+ Clearly identifies the cause and provides concise, safe cleanup code.

- The fallback key may collide, and messages are not reset on room changes.

Gemini
39/ 50

+ Broadly reviews room changes, parsing, keys, and socket handling.

- It ignores React-version differences and overstates parsing as a component crash.

CriterionChatGPTGeminiLeader
Instruction following99Tie
Accuracy97ChatGPT +29%
Specificity99Tie
Structure98ChatGPT +13%
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]
React 컴포넌트인데 다른 페이지로 이동했다가 돌아오면 콘솔에 경고가 쌓입니다. 원인 좀 봐주세요.

```jsx
function ChatRoom({ roomId }) {
  const [messages, setMessages] = useState([]);

  useEffect(() => {
    const socket = new WebSocket(`wss://chat.example.com/${roomId}`);
    socket.onmessage = (e) => {
      setMessages(prev => [...prev, JSON.parse(e.data)]);
    };
  }, [roomId]);

  return <ul>{messages.map((m, i) => <li key={i}>{m.text}</li>)}</ul>;
}
```
gpt-5.6-luna (codex CLI · 에이전트 하네스) · Run on 2026-09-24

원인은 useEffect에서 생성한 WebSocket을 정리하지 않는 것입니다. 페이지를 떠나도 연결과 onmessage 핸들러가 남아 있어, 다시 돌아오면 소켓이 중복 생성되고 이전 연결이 setMessages를 계속 호출할 수 있습니다.

import { useEffect, useState } from "react";

function ChatRoom({ roomId }) {
  const [messages, setMessages] = useState([]);

  useEffect(() => {
    const socket = new WebSocket(
      `wss://chat.example.com/${encodeURIComponent(roomId)}`
    );

    let active = true;

    socket.onmessage = (event) => {
      if (!active) return;

      try {
        const message = JSON.parse(event.data);
        setMessages((prev) => [...prev, message]);
      } catch {
        console.error("잘못된 WebSocket 메시지:", event.data);
      }
    };

    socket.onerror = (error) => {
      console.error("WebSocket 오류:", error);
    };

    return () => {
      active = false;
      socket.onmessage = null;
      socket.onerror = null;

      if (
        socket.readyState === WebSocket.OPEN ||
        socket.readyState === WebSocket.CONNECTING
      ) {
        socket.close();
      }
    };
  }, [roomId]);

  return (
    <ul>
      {messages.map((message) => (
        <li key={message.id ?? `${message.timestamp}-${message.text}`}>
          {message.text}
        </li>
      ))}
    </ul>
  );
}

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

  • key={i}는 메시지 삽입·삭제 시 잘못된 DOM 재사용을 유발할 수 있으므로 서버 메시지의 고유 ID를 사용하세요.
  • JSON.parse는 외부 데이터이므로 예외 처리가 필요합니다.
  • 개발 환경의 React Strict Mode에서는 effect가 의도적으로 실행·정리·재실행되어, cleanup 누락 문제가 더 쉽게 드러납니다.
  • 서버가 자동 재연결을 지원한다면 재연결 로직도 cleanup 시 반드시 중단해야 합니다.

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