“AI ไม่ได้มาแย่งงาน reviewer… แต่มันกำลังเปลี่ยนวิธีที่เราคุยกับโค้ดตัวเอง”
บทนำ
ทุกคนที่เคยทำงานในทีม dev คงคุ้นกับคำว่า Code Review
กิจกรรมที่เราส่ง PR แล้วรอ reviewer มา comment ด้วยความหวังดี (แต่บางทีก็แทงใจดำ 😅)
แต่ในโลกยุคใหม่ — ที่ทุก commit วิ่งเร็วกว่าความคิด
ทีมหลายทีมเริ่มมี “เพื่อนใหม่” ที่มาช่วย review ก่อน reviewer ตัวจริงจะเห็นด้วยซ้ำ
นั่นคือ “AI Reviewer” หรือ “AI Pair Review Model”
ไม่ใช่แค่บอกว่า code ทำงานได้หรือไม่
แต่ช่วยเราคิดว่า “ทำไมมันควรเขียนแบบนี้แทน”
AI Reviewer คืออะไร?
ลองจินตนาการว่าเรามี reviewer ที่ไม่หลับ ไม่หงุดหงิด ไม่บ่นเรื่อง spacing
แต่ถามกลับมาแบบเข้าใจบริบท เช่น…
“method นี้มี side effect รึเปล่า?”
“logic นี้ควรอยู่ใน Service แทน Controller นะ”
“ถ้าเกิด exception ตรงนี้ rollback จะยังทำงานไหม?”
AI Reviewer คือเครื่องมือที่ใช้ LLM (Large Language Model)
อ่านโค้ดทั้งไฟล์ หรือทั้ง PR แล้วสรุป insight กลับมาเหมือน reviewer คนจริง ๆ
ทำไมมันถึงสำคัญ
ทุกทีม dev เคยเจอปัญหาแบบนี้แน่ ๆ 👇
- reviewer แต่ละคนมี style ไม่เหมือนกัน
- บาง PR ต้องรอ 2–3 วันถึงจะได้ feedback
- comment หลายอันเป็น pattern เดิม ๆ เช่น “check null ก่อนสิ”, “อย่าทำ business logic ใน controller”
AI ช่วย “เก็บ pattern review ที่ซ้ำซาก” ออกไป
ปล่อยให้ reviewer ตัวจริงโฟกัสกับ logic เชิง design หรือ domain แทน
พูดง่าย ๆ คือ AI ไม่ได้แทน reviewer
แต่มันคือ reviewer ที่ review ก่อน reviewer อีกที
Flow การใช้งานจริง (Zengcode Style)
สมมติเรามี PR สำหรับ Order Service
@RestController
@RequiredArgsConstructor
public class OrderController {
private final OrderService orderService;
@PostMapping("/orders")
public ResponseEntity<String> create(@RequestBody Order order) {
orderService.save(order);
return ResponseEntity.ok("created");
}
}
เราส่งให้ AI Review ด้วย Prompt ประมาณนี้ 👇
You are a senior backend developer.
Please review this Spring Boot code.
Focus on:
- Design and architecture smell
- Transaction and error handling
- Code readability and maintainability
ผลลัพธ์จาก AI (ย่อ):
- ควรใช้ DTO แทนการรับ entity ตรง ๆ
- ไม่มี validation ก่อน save
- ไม่ควร return String ตรง ๆ ควรมี response object
- method name “save” ไม่ชัดเจนสำหรับ use case
อ่านแล้วรู้เลยว่า… AI มันจับประเด็นได้เหมือน dev senior จริง ๆ 🔥
ทำให้ AI Review “เหมือน Senior Dev” ต้องทำยังไง
ถ้าอยากให้ AI มี output ที่ดี — อย่าป้อนโค้ดเปล่า ๆ
เพราะ โค้ดไม่มีบริบท = comment ก็มั่ว
ให้ป้อน context ไปด้วยแบบนี้:
Project context:
- Stack: Spring Boot + JPA + Kafka
- Purpose: Order service, event-driven
- Focus: Clean architecture and maintainability
Code:
...
แค่ใส่ context เพิ่มนิดเดียว
AI จะเริ่มพูดภาษาคนจริงขึ้นเยอะ เช่น
“service นี้ควรแยก publish event ออกจาก transaction เพื่อป้องกัน duplicate event”
ทำไม Dev ควรเริ่มลองใช้ AI Review ตอนนี้
1️⃣ มันช่วย “ส่องมุมที่เรามองข้าม” ได้ดีมาก
2️⃣ ทำให้เราเข้าใจแนวคิด Clean Code ผ่าน feedback ที่ personalized
3️⃣ ช่วยลดเวลา review pattern เดิม ๆ
4️⃣ เป็นครูสอน design pattern โดยไม่รู้ตัว
และสิ่งที่ชอบที่สุดคือ —
AI ไม่มี ego ไม่มีอารมณ์ มัน comment ด้วย logic ล้วน ๆ 😄
Tools ที่ใช้ได้จริง
- GitHub Copilot Chat: เปิด diff แล้วพิมพ์
/review
→ มันจะวิเคราะห์ให้ทั้งไฟล์ - Cursor IDE: select โค้ด แล้วพิมพ์ “review this method” ได้ทันที
- ChatGPT (GPT-5): ใช้ context + prompt custom ได้ยืดหยุ่นมาก
- LangChain4j / Custom API: สำหรับต่อเข้ากับ pipeline ของ Jenkins หรือ PR workflow
ลองฝึกให้ AI เป็น reviewer คู่ประจำ —
มันจะจำสไตล์เราได้เรื่อย ๆ เหมือนเพื่อนร่วมทีมที่รู้ใจ
ตัวอย่างการฝึก AI ให้ “รู้สไตล์เรา”
Prompt สำหรับฝึกให้ AI เข้าใจ code base ของเรา:
You are a reviewer who knows our coding style:
- Layered architecture (Controller → Service → Repository)
- Naming convention: verbs for commands, nouns for queries
- We use DTOs, not entities in controllers
Please review the following PR and suggest improvements.
AI จะเริ่ม feedback ตามสไตล์เราโดยอัตโนมัติ
แทนที่จะพูดว่า “bad practice” — มันจะบอกว่า
“ตาม style ของทีมนี้ method นี้ควรอยู่ใน ApplicationService”
ซึ่งนั่นแหละ คือจุดที่ AI เริ่มเป็น teammate จริง ๆ
AI Review Process Diagram (ภาพรวมการไหลของงาน)
[Developer Commit Code]
↓
[Create Pull Request]
↓
[AI Reviewer Analyzes Code]
↓
[AI Suggests Feedback → Design / Clean Code / Risk]
↓
[Developer Reviews AI Suggestions]
↓
[Human Reviewer Adds Domain Feedback]
↓
[Code Merge & Continuous Improvement]
🔁 จุดแข็งของ flow นี้คือ feedback loop ที่สั้นมาก — AI จะช่วย filter สิ่งพื้นฐานก่อน ถึงมือ reviewer จริ
ข้อควรระวัง
AI ยังมีข้อจำกัดนะครับ
- มันยังไม่เข้าใจ business logic ลึก ๆ เหมือนมนุษย์
- มันอาจแนะนำสิ่งที่ “ถูกเชิง syntax” แต่ “ผิดเชิง domain”
และที่สำคัญ: อย่าเชื่อมัน 100% แต่ใช้มันเพื่อคิดได้ลึกขึ้น
เพราะสุดท้ายแล้ว Reviewer ที่ดีที่สุด…
ก็ยังคือ “สมองของเรา” นั่นแหละ 💪
สรุปสไตล์ Zengcode
AI ไม่ได้ทำให้เราขี้เกียจ review
แต่มันทำให้เรามีเวลาคิดเรื่องที่ใหญ่กว่านั้น
แทนที่จะ comment เรื่อง spacing, naming, หรือ logic เล็ก ๆ
เราได้เอาเวลาไปคิดว่า “โค้ดนี้สะท้อน business ที่ถูกต้องไหม?”
และนั่นแหละคือจุดที่ Dev คนหนึ่ง… กำลังเติบโตขึ้นพร้อม AI 🌱
#AIForDev #AICodeReview #DeveloperExperience #CleanCode #SoftwareEngineering #CursorIDE #GitHubCopilot #SpringBoot #Zengcode #ThaiJavaZone
Learn more about AI Code Review — เมื่อคู่หูของคุณไม่ใช่ Reviewer แต่เป็น Model