| | |
Summary: Style in Java
Basic principles
Readability is the most important attribute of style
Choose good names. The most direct way of explaining what a program is about is by selecting good
names for variables, types, procedures, etc. If I'm trying to write some new code, and I can't figure out a
good name for a class or method, I'll often be stuck until I have something. Many times, I find that the
reason I can't pick a good name is that I don't understand enough about what I'm trying to say; with
understanding comes good names, and vice versa. Don't use abbreviations
Code so that changes will be easier.
Formatting
1. Indent (four spaces) to show organizational structure of code.
2. Blank lines improve readability by setting off sections of code that are logically related.
3. Two blank lines should always be used in the following circumstances:
a. Between sections of a source file
b. Between class and interface definitions
4. One blank line should always be used in the following circumstances:
|