Follow these tips for good programming style. Each item below will be
considered when assignments are graded. More importantly, programs that
follow these recommendations will be easier to read, easier to
understand, and easier to debug.
General
- Follow standard Javadoc style conventions. (Comment every class and
class member. Use
@author
, @version
,
@param
, and @return
as appropriate.)
- Use curly braces and indentation properly and consistently.
- Always start a new line and indent after an open curly brace.
- Always start a new line after a closing curly brace, except for else
in a conditional structure or while in a
do... while
structure.
- Open curly brace may come at the end of a line (compact style) or
always on its own line (loose style).
- Closing curly brace should always start its own line, and should be
outdented to undo the indent from the open brace that it matches.
- Eliminate unnecessary repetition.
- In a tradeoff between clarity and efficiency, choose
clarity.
- This style
guide from the University of Hawaii goes into further detail on many
areas.
Naming
- Give variables clear, descriptive names that describes what
information they hold.
- Name methods according to what the method does.