Step 51 of 51
How to review code for correctness, readability, and cognitive load. Practical checklist, naming conventions, and feedback rules.
Code review ช่วยทั้งหา bug ปรับโค้ดให้อ่านง่าย และลด cognitive load ให้คนที่มาอ่านต่อ
Last verified: June 2026
Code is read 10x more than it's written. Every change either reduces or increases the cognitive load for the next person who touches it.
Scan in this order — fastest to slowest:
Every variable, condition, and abstraction adds to the reader's working memory. Fewer things to hold = easier to maintain.
| Problem | Fix |
|---|---|
| Long function (40+ lines) | Extract sub-functions with descriptive names |
| Nested conditionals (3+ levels) | Guard clauses / early returns |
Vague names (data, result, temp) | Specific names (unpaidInvoices, retryCount) |
| Boolean flag parameters | Split into separate functions |
| Comment explains WHAT | Code should explain what — comment explains WHY |
| Too many parameters (5+) | Group into an object/record |
// Bad — requires reading the method to understand
process(document, true, 3);
// Good — reads itself
validateAndRetry(document, maxAttempts: 3);
A function should do ONE thing at ONE level of abstraction. If you can't describe it in one sentence without "and", it's doing too much.
blocking: and nit: prefixesStop and look closer when you see:
// TODO or // FIXME in shipped code