CIT 590 Style Rules
Spring 2009, David Matuszek
Names
- Variables start with a lowercase letter and are in
camelCase.
- Class and interface names start with a capital letter
and are in
CamelCase.
- Constants (
final variables) are written with ALL_CAPITALS_AND_UNDERSCORES.
Indentation
Spaces
Put a single space:
- Before and after any binary operator except "dot":
+
- * / % = && || and several others.
- After commas, colons, and semicolons (except at the end of a line).
- Between a keyword and an open parenthesis (for example,
while
( ).
- Before an open brace,
{.
Do not put a space:
- On either side of a dot.
- Between a method name and its parameter list (example:
scanner.nextInt(6) ).
- Immediately inside parentheses (example: do not write
2
+ ( 3 * y ) ).
- Before a comma, colon, or semicolon.
Semantic:
- Don't write "clever" code--make it as readable as you can.
- Keep computations and input/output in separate methods.
- Names should be meaningful (exception: indices of
for loops
should be i, j, k).
- Avoid magic numbers--give them meaningful variable names.
- Do not use abbreviations (unless common and well known, such as
max for maximum).
- Keep methods short enough to see the entire method at once (about 50
lines at most).