3.5 Iterative Refinement Techniques
Iterative Refinement คืออะไร
Iterative Refinement คือเทคนิคการทำงานกับ Claude แบบวนรอบ — ทำ → ทดสอบ → ดู feedback → แก้ → ทดสอบอีก — จนกว่าจะได้ผลลัพธ์ที่ต้องการ แทนที่จะพยายามได้ perfect output ตั้งแต่ครั้งแรก เราใช้ feedback loops ช่วย guide Claude ไปทีละ step
Test-Driven Development with Claude
Pattern ที่ effective ที่สุดคือ: เขียน test ก่อน → ให้ Claude implement → run test → ถ้า fail ส่ง error กลับให้ Claude แก้:
1. User: "เขียน test สำหรับ calculateTax function"
2. Claude: เขียน test file
3. User: "ตอนนี้ implement calculateTax ให้ pass tests เหล่านี้"
4. Claude: เขียน implementation
5. Claude: run tests → FAIL
6. Claude: ดู error → แก้ code → run tests → PASS
ตัวอย่าง Workflow
# Claude เขียน test ก่อน
cat tests/tax.test.ts
# Claude implement
cat src/tax.ts
# Run tests - feedback loop
pnpm test tests/tax.test.ts
# FAIL: expected 700 but got 0
# Claude เห็น error → แก้ → run อีก
pnpm test tests/tax.test.ts
# PASS
Feedback Loop Patterns
1. Test Output Loop
ให้ Claude run tests แล้ว iterate จาก error messages:
- Test failures บอก exactly ว่าอะไรผิด
- Claude fix → test again → repeat
2. Lint/Type Check Loop
run lint → fix warnings → run lint → clean
run tsc → fix type errors → run tsc → clean
3. Build Error Loop
build → see error → fix → build → success
4. User Feedback Loop
Claude: "นี่คือ implementation"
User: "ดีแล้ว แต่เพิ่ม error handling ด้วย"
Claude: เพิ่ม error handling
User: "ดี แต่ edge case X ยังไม่ cover"
Claude: เพิ่ม edge case handling
Progressive Enhancement
เริ่มจาก simple implementation แล้ว layer complexity ทีละ step:
Step 1: Basic happy path (CRUD operations)
Step 2: Add validation
Step 3: Add error handling
Step 4: Add logging
Step 5: Add tests
Step 6: Add documentation
แต่ละ step ทำ → ทดสอบ → confirm ก่อนไป step ถัดไป
Techniques for Effective Iteration
- Small commits — commit ทุก step ที่ work เพื่อ rollback ได้
- Clear error messages — ส่ง full error output ให้ Claude (ไม่ต้อง summarize)
- One thing at a time — fix one issue per iteration
- Regression testing — run full test suite ไม่ใช่แค่ test ที่เพิ่งเพิ่ม
Key Concepts
- Feedback-driven — ใช้ concrete feedback (test results, errors) guide Claude
- Incremental — ทำทีละ step ไม่ใช่ทั้งหมดพร้อมกัน
- Verifiable — ทุก step มีวิธี verify ว่า correct
- Reversible — commit บ่อยเพื่อ rollback ได้ถ้าไป wrong direction
Exam Tips
- TDD with Claude = เขียน test ก่อน → implement → iterate from failures
- ข้อสอบอาจถามว่า technique ไหน effective ที่สุดสำหรับ iterative refinement — ตอบ: ใช้ concrete feedback (test output, compiler errors) ไม่ใช่ vague descriptions
- Claude ทำงานดีที่สุดเมื่อเห็น exact error message — ส่ง raw output ไม่ต้อง interpret ให้
- Progressive enhancement = start simple, add complexity iteratively
- ทุก iteration ควร testable — ไม่ใช่แค่ “looks right”