+ Separates facts from inference and catches the reactivity trap.
- Slightly long, and a few suggested follow-up files are speculative.
Starts from what the whole thing does, then the flow — and names what you still have to read elsewhere.
| Category | Development › Coding |
|---|---|
| Tags | AnalyzingDeveloperCode |
Help me understand this code. Order: 1. ***What the whole thing does, in three lines.*** **Start here.** 2. Entry point and flow of execution — where it starts and where it goes 3. What each major part does. **In blocks, not line by line** 4. What it depends on — external libraries, config, other modules 5. ***What is needed to understand it and is not visible here*** — which files I should read next 6. Why it was written this way, where you can infer it (**mark inference as inference**) 7. Where to be careful when changing it Rules: - Pitch it at my level given below. - ***Do not invent behavior that is not in the code.*** Where unsure, mark it "needs checking".
Line-by-line explanation does not tell you what the code is for. This goes whole-first and marks inference as inference.
ChatGPT is strongest, accurately identifying price and subscription pitfalls. Gemini is thorough but verbose and occasionally overstated; [C] was not provided.
+ Separates facts from inference and catches the reactivity trap.
- Slightly long, and a few suggested follow-up files are speculative.
+ Concrete Java-oriented analogies and risk explanations.
- Verbose, with overly categorical claims about subscriptions and mutation.
| Criterion | ChatGPT | Gemini | Leader |
|---|---|---|---|
| Instruction following | 10 | 9 | ChatGPT +11% |
| Accuracy | 9 | 7 | ChatGPT +29% |
| Specificity | 10 | 9 | ChatGPT +11% |
| Structure | 9 | 8 | ChatGPT +13% |
| Right length | 8 | 6 | ChatGPT +33% |
Scored 1–10 by gpt-5.6-sol with model names hidden (2026-09-24). This is an AI review, not a measurement.
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.
My level: 백엔드 3년차(Java/Spring 위주), React는 이번 프로젝트에서 처음 접함
Language and framework: React 18 + TypeScript, Vite, 상태관리는 Zustand, 스타일은 Tailwind
Code: import { create } from 'zustand';
interface CartItem {
productId: string;
quantity: number;
price: number;
}
interface CartState {
items: CartItem[];
addItem: (item: CartItem) => void;
removeItem: (productId: string) => void;
totalPrice: () => number;
}
export const useCartStore = create<CartState>((set, get) => ({
items: [],
addItem: (item) => set((state) => {
const existing = state.items.find((i) => i.productId === item.productId);
if (existing) {
return {
items: state.items.map((i) =>
i.productId === item.productId
? { ...i, quantity: i.quantity + item.quantity }
: i
),
};
}
return { items: [...state.items, item] };
}),
removeItem: (productId) =>
set((state) => ({ items: state.items.filter((i) => i.productId !== productId) })),
totalPrice: () => get().items.reduce((sum, i) => sum + i.price * i.quantity, 0),
}));이 코드는 Zustand로 장바구니 상태를 전역 관리하는 스토어를 만든다.
상품 추가 시 같은 productId가 있으면 수량을 합치고, 없으면 새 항목을 추가한다.
상품 삭제와 전체 금액 계산 기능도 제공한다.
이 파일 자체의 진입점은 다음 export입니다.
export const useCartStore = create<CartState>(...)
컴포넌트에서 이 스토어를 import하고 호출하면서 사용합니다.
const items = useCartStore((state) => state.items);
const addItem = useCartStore((state) => state.addItem);
흐름은 다음과 같습니다.
create가 스토어를 생성합니다.items: []입니다.useCartStore(selector)를 호출해 상태나 함수를 구독합니다.addItem, removeItem이 호출되면 set이 상태를 갱신합니다.totalPrice()가 호출되면 현재 items를 기준으로 금액을 계산합니다.interface CartItem
interface CartState
장바구니 항목과 스토어의 형태를 정의합니다.
CartItem은 다음 데이터를 가집니다.
productId: 상품 식별자quantity: 수량price: 단가CartState는 장바구니 목록과 세 가지 동작을 정의합니다.
create<CartState>((set, get) => ({
...
}))
Zustand 스토어를 생성합니다.
set: 상태를 변경할 때 사용get: 현재 상태를 읽을 때 사용<CartState> 때문에 스토어의 상태와 함수가 타입 검사를 받습니다.
addItem: (item) => set((state) => {
const existing = state.items.find(...)
...
})
먼저 같은 productId를 가진 상품이 있는지 찾습니다.
이미 있으면:
items: state.items.map(...)
기존 배열을 직접 수정하지 않고 새 배열을 만들면서 해당 상품의 quantity만 증가시킵니다.
없으면:
items: [...state.items, item]
기존 항목을 유지한 채 새 상품을 배열 뒤에 추가합니다.
removeItem: (productId) =>
set((state) => ({
items: state.items.filter(...)
}))
전달받은 productId와 다른 항목만 남깁니다. 즉, 해당 상품을 장바구니에서 완전히 제거합니다.
totalPrice: () =>
get().items.reduce(
(sum, i) => sum + i.price * i.quantity,
0
)
현재 장바구니의 각 항목에 대해 다음을 더합니다.
price × quantity
장바구니가 비어 있으면 0을 반환합니다.
코드에서 직접 보이는 외부 의존성은 다음 하나입니다.
import { create } from 'zustand';
zustand: 전역 상태 저장소 생성useCartStore를 호출할 수 있도록 함프로젝트 환경인 React 18, TypeScript, Vite와 함께 사용되지만 이 코드 자체에서 React나 Vite를 직접 import하지는 않습니다.
Tailwind도 이 파일의 상태 로직에는 관여하지 않습니다.
추가로 필요한 설정이나 미들웨어가 있는지는 package.json, Zustand 설정 파일을 확인해야 합니다. 현재 코드만으로는 별도 미들웨어 사용 여부는 알 수 없습니다.
이 코드의 실제 사용 방식은 이 파일만으로 완전히 알 수 없습니다. 다음 순서로 찾으면 됩니다.
package.jsonuseCartStore를 import하는 파일CartItem을 생성하는 상품 목록 또는 상세 컴포넌트price와 quantity가 어디서 오는지productId, 가격의 타입과 의미main.tsx, App.tsx 또는 라우팅 설정프로젝트에서 다음 검색을 하면 사용처를 찾을 수 있습니다.
rg "useCartStore|addItem|removeItem|totalPrice" src
다음은 코드에서 직접 확인되는 사실과 그로부터의 추론을 구분해야 합니다.
items를 직접 수정하지 않고 map, filter, 전개 연산자로 새 배열을 만듭니다.productId 기준으로 수량을 합칩니다.totalPrice를 상태에 저장하지 않고 호출 시 계산합니다.items와 합계가 서로 어긋나는 문제를 피하려는 설계로 보입니다. (추론)totalPrice는 값이 아니라 함수입니다.items를 읽기 위해 이렇게 작성한 것으로 보입니다. (추론)다만 다음은 코드만으로 의도를 확정할 수 없습니다.
quantity === 0일 때 삭제할지 — needs checkingstate.items를 직접 push, splice로 수정하지 않는 것이 안전합니다. 현재처럼 새 배열을 반환해야 합니다.price는 유지됩니다. 새로 전달된 item.price로 갱신되지 않습니다.removeItem은 수량을 하나 줄이는 것이 아니라 상품 전체를 제거합니다.quantity가 음수이면 합계가 잘못 계산될 수 있습니다. 입력 검증은 이 코드에 없습니다.price가 원 단위 정수인지, 소수점 금액인지 확인해야 합니다. 소수점 금액을 JavaScript number로 계산할 때 금액 오차가 생길 수 있습니다.totalPrice를 컴포넌트에서 호출할 때는 보통 다음처럼 사용합니다.const totalPrice = useCartStore((state) => state.totalPrice);
const price = totalPrice();
totalPrice 자체를 구독하는 것과 그 함수가 읽는 items의 변경을 구독하는 것은 별개의 문제일 수 있으므로, 실제 사용 방식은 확인이 필요합니다.
| 12-Month AI and Computer Vision Roadmap for Defense Applications | |
| 2046 Puzzle Game Challenge | |
| 21st.dev component prompt | |
| 3D FACTORY | |
| 3D FPS Game |