Skip to content
Lauren Ko edited this page Oct 28, 2015 · 5 revisions

🚧 This document is a work in progress 🚧

The coding style conventions that OpenWayback should follow is based on the document Sun's Code Conventions for the Java Programming Language. We have loosened some of the requirements and strengthened others. Most important points are listed below.

Code Style

  • Use spaces, not tabs. Tabs should not appear in project source code.
  • Indent 4 spaces per level.
  • (Deviation from Sun recommendations) Lines should not be longer than 100 columns. Sun recommends 80, but screens have grown larger. Since method and variable names shouldn't be abbreviated, lines tend to be broken too frequently if they are only 80 columns.
  • No spaces at end of line
  • Files should end with newline
  • Place the opening bracket for a code block on the same line as the declaration/test expecting a block.
  • Use brackets even when a branch/block is only a single line of code (to provide an additional visual cue, and for robustness if other lines are added later).
  • Prefer longs over ints anywhere a large count of artifacts or large-sized file/range is possible.
  • Prefer 'package private' (i.e. no modifier) over 'private' unless a consideration of potential subclass use suggests direct access will be dangerous.
  • (Deviation from Sun recommendations) It is permissible to declare local variables as close to first use as practical (as opposed to at the start of the enclosing block).
  • (Deviation from some recommendations) Early- and multiple- returns from methods are encouraged to minimize indention-levels, and handle simple or error cases quickly.
  • All classes and methods should have Javadoc comments. See Sun's style guide for Javadoc for tips on good Javadoc comments.
  • Avoid broad catches (of all Exception or all Throwable) where possible. (Testing code and other all-or-nothing situations excepted.)

Tip

This style guide was not enforced from the start and therefor it might sometimes be difficult to sort out real changes from changes in formatting, especially changes in white space. Everywhere on GitHub where there is a diff view (like in pull requests) you can add ?w=1 at the end of the line to ignore changes in white space from the view.