Clean Code: Meaningful Names 清晰有意义的命名

Categories: Development NotesJava; Tagged with: ; @ August 14th, 2013 0:02

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.

Uncle Bob

Summary for Clean Code chapter 2:

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

Java Code Quality Control Eclipse Plugins 代码质量控制Eclipse插件

Categories: Development NotesJava; Tagged with: ; @ May 2nd, 2013 22:04

Several Eclipse plugins which can help to improve code quality.  all plugs can find from Eclipse Market.

1.  FindBugs

Find potential bugs for you.  “a program which uses static analysis to look for bugs in Java code

image

2. eCobertura

“eCobertura is a free Eclipse plugin for Cobertura – a Java code coverage reporting tool.”

With “eCobertura”, we can get an overview of code coverage within Eclipse.

image

BTW, This plugin hasn’t been updated for more than 2 years.

How to clear the code coverage highlighting?
Currently, no this feature (https://github.com/jmhofer/eCobertura/issues/8), but can reset by edit the java class.

3. CheckStyle

Help developer to check the coding style, for example, coding conversation, make sure the code is clean and neat.

Checkstyle is a development tool to help programmers write Java code that adheres to a coding standard. It automates the process of checking Java code to spare humans of this boring (but important) task. This makes it ideal for projects that want to enforce a coding standard.

image

 

[to be continued]



// Proudly powered by Apache, PHP, MySQL, WordPress, Bootstrap, etc,.