White Space
Blank lines improve readability by setting off sections of code that are logically related.
Two blank lines should always be used between sections of a source file. That is, two blank lines should follow:
· The opening comment
· The package statement
· The import statements
· The class and interface declaration
One blank line should always be used in the following circumstances:
· Between methods
· Between the local variables in a method and its first statement
· Before a block or single-line comment.
· Between logical sections inside a method to improve readability.
· Use common sense and don't be afraid to put blank lines!
Blank Spaces
- Blank spaces should be used in the following circumstances:
- A blank space should appear after commas in argument lists.
- All binary operators except. Should be separated from their operands by spaces. Blank spaces should never separate unary operators such as unary minus, increment ("++"), and decrement ("--") from their operands.
- The expressions in a "for" statement should be separated by blank spaces.
Example:
|
Parentheses
It is generally a good idea to use parentheses liberally in expressions involving mixed operators to avoid operator precedence problems
|
--
No comments:
Post a Comment