Programming code
- For variable name, always use English with lowerCamelCase.
space in comment:
bad example:
It is better to explain the problem clearly in Chinese than to make it half-assed in English. Proper nouns and keywords should be kept in English.
Comment out code carefully. Explain in detail at the top, rather than simply commenting it out. If no, delete it. Note: There are two possibilities for code to be commented out: 1) the code logic will be restored later. 2) Never use it. If there is no comment information, it is difficult to know the annotation motivation. The latter suggests simply deleting it (the repository holds historical code).
- 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{}Copy the code
- 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;
Copy the code
Better to use if XXX return; instead of if XXX else YYY:
Reference documentation
Alibaba Java development manual ultimate edition V1.3.0
More of Jerry’s original articles can be found in “Wang Zixi” :