Clean Code
Code that is easy to understand, simple to modify, and clearly expresses the intent of the programmer. A philosophy popularized by Robert C. Martin.
定义
Clean code follows principles from Robert Martin's book "Clean Code": meaningful names, small focused functions, clear intent, minimal dependencies, and no duplication (DRY). Clean code reads like well-written prose — each function tells a story at its level of abstraction. The Boy Scout Rule says to always leave code cleaner than you found it.
为什么重要
Developers spend 10x more time reading code than writing it. Clean code reduces this cognitive load, making maintenance faster and less error-prone. Studies show teams with clean code practices have 50% fewer bugs and onboard new developers 3x faster.
示例
Instead of: function calc(a,b,c) { return a*b-c/2; } — clean code would be: function calculateDiscountedTotal(subtotal, discount, tax) { return subtotal * discount - tax / 2; }