Tools
Clean Code: หลักการเขียนโค้ดที่ดีที่ทุก Developer ต้องรู้
นิรันดร์ โค้ด
2026-06-14
1. ตั้งชื่อให้สื่อความหมาย
// Bad
int d; // elapsed time in days
// Good
int elapsedTimeInDays;
2. ฟังก์ชันควรทำแค่อย่างเดียว
Single Responsibility Principle: ฟังก์ชันหนึ่งควรทำงานหนึ่งอย่างเท่านั้น
3. หลีกเลี่ยง Magic Numbers
const MINIMUM_AGE = 18;
if ($user->age > MINIMUM_AGE) { ... }
"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." — Martin Fowler