🧭 Dev Naming Convention Handbook
คู่มือรูปแบบการตั้งชื่อทั้งหมดที่ใช้บ่อยที่สุดในสายงานพัฒนาโปรแกรม
🎯 ทำไมต้องมีรูปแบบการตั้งชื่อ
- เพื่อให้ทีมเข้าใจตรงกัน
- เพิ่มความเป็นระเบียบในโปรเจกต์
- ช่วยให้โค้ดอ่านง่าย และค้นหาได้เร็ว
- รองรับการทำงานร่วมกันแบบมืออาชีพ
🔡 รูปแบบการตั้งชื่อที่นักพัฒนาควรรู้
ชื่อรูปแบบ | ตัวอย่าง | ใช้ในกรณี |
---|---|---|
camelCase | userName , isLoading | ตัวแปร, ฟังก์ชัน |
PascalCase | UserProfile , LoginForm | class, component |
snake_case | user_id , created_at | database (table/column), Python |
kebab-case | user-profile , post-detail | ชื่อไฟล์, โฟลเดอร์, URL |
SCREAMING_SNAKE_CASE | MAX_LIMIT , API_KEY | ค่าคงที่ (constant) |
dot.case | config.dev.json , settings.prod.ts | config files (บางประเภท) |
🧪 ตัวอย่างการใช้งาน
camelCase
const userEmail = "[email protected]";
function getUserData() {}
PascalCase
class UserProfile {}
const AppHeader = () => <header />;
snake_case
SELECT * FROM users WHERE created_at > NOW();
kebab-case
GET /api/user-profile
components/user-card/
SCREAMING_SNAKE_CASE
const AUTH_TOKEN_KEY = "abcd1234";
dot.case
// config.dev.json
{
"apiBaseUrl": "https://dev.example.com"
}
📌 สรุปการใช้แต่ละรูปแบบ
บริบท | รูปแบบแนะนำ |
---|---|
ตัวแปรทั่วไป | camelCase |
ฟังก์ชัน | camelCase |
คลาส / Component | PascalCase |
Database (table/column) | snake_case |
ชื่อไฟล์ / URL / folder | kebab-case |
ค่า constant | SCREAMING_SNAKE_CASE |
config file name | dot.case |
🚀 สร้างมาตรฐานให้ทีม เริ่มจากการตั้งชื่อ
รูปแบบการตั้งชื่อไม่ใช่เรื่องเล็ก แต่มันคือ "ภาษากลาง" ของทุกคนในทีม แนะนำให้นำบทความนี้ไปปรับใช้และกำหนดเป็น Standard ภายในทีม Dev ของคุณ