编程规约
- For variable name, always use English with lowerCamelCase.

space in comment:

bad example:

Suggestion: 与其“半吊子”英文来注释,不如用中文注释把问题说清楚。专有名词与关键字保持英文原文即可。
谨慎注释掉代码。在上方详细说明,而不是简单地注释掉。如果无用,则删除。 说明:代码被注释掉有两种可能性:1)后续会恢复此段代码逻辑。2)永久不用。前者如果没有备注信息,难以知晓注释动机。后者建议直接删掉(代码仓库保存了历史代码)。
-
Do not mix production code with test code. All testing codes must be put to folder src\test\java.
-
Constant:



-
For boolean variable in POJO, no "is" prefix is allowed.
-
Always use meaningful naming for self-descriptive purpose.

Bad example: no prefix for local variable.

- Naming per layer

- Bracket usage
if( XXX ){
yyy;
}
if( XXX ){
yyy;
} else{
}
- space usage

bad example:

space between method and argument:

bad example:

- new line usage
guideline:

bad example:

- text file encoding
IDE text file encoding: UTF-8; IDE new line format: use Unix instead of Windows
IDE setting:

why we should set this property
- basic type and wrapper object

-
No business logic is allowed in constructor. If initialization logic is needed, put it in init().
-
class method sequence
public method > protected > private > getter / setter

- No business logic in setter/getter

- Bracket is mandatory in if/else/for/while/do.
Bad example:
if (condition) statements;
Better to use if XXX return; instead of if XXX else YYY:

参考文档
更多Jerry的原创文章,尽在:"汪子熙":

网友评论