One difference between a smart programmer and a professional programmer is that the professional understands that clarity is king . Professional use their powers for good and write code that others can understand.
Use Intention-Revealing names 表明意图
int d; –> int daysSinceCreation;
list1 –> flaggedCells
Avoid Disinformation 提供真实信息
accountList: Unless it’s actually a List. otherwise, accountGroup/bunchOfAccounts/accounts would be better
Make meaningful distinctions 有意义的区分
copyChars(a1, a2) –> copyChars(source, destination)
Use Pronounceable Names 使用可以发音的变量名称
luo –> lastUpdatedOn
Hungarian notation 匈牙利命名法 不必再刻意添加前缀
strName –> name
m_desc –> desc
Class names: noun or noun phrase. Method names, verb or verb phrase.
Don’t be cute 清晰表达即可, 不要画蛇添足
eatMyShorts() –> abort() [Eat my shorts, by Bart Simpson]
Pick One Word per Concept 为一个概念选定一个名称 Don’t pun 不要使用双关词汇
fetch, get
add, insert?
Use Solution Domain Names 使用解决方案领域内词汇
AccountVisitor, StudentFactory
Add Meaningful Context 有意义的语境, Don’t Add Gratuitous Context 但不要增加无意义的上下文
Class name: SGMailingAddress –> MailingAddress
// Proudly powered by Apache, PHP, MySQL, WordPress, Bootstrap, etc,.