Java Style Guide

dwdyer edited this page Sep 13, 2010 · 2 revisions

If you want to contribute code to the Watchmaker project, please adhere to the following coding standards.

The short version of this document is that any new code should be formatted the same way as the existing code. Other than brace placement, this is broadly similar to the standard Sun Java coding conventions.

Currently the project builds and runs with Java 5.0. We intend to keep it that way for the foreseeable future, so please don’t introduce dependencies on later versions of Java.

Braces

  • All opening and closing braces must be on a new line by themselves (i.e. not K&R style).
  • All blocks must have braces (i.e. no single-line ifs).

Imports

  • No wildcard (org.blah.*) imports.
  • Imports should be listed strictly in alphabetical order with no blank lines separating them (i.e. no grouping of core, project and third-party packages).

Comments

  • No C-style (/* ... */) mutli-line comments, use multiple C++ style (//) single-line comments instead.

Indentation and Layout

  • Indent only with spaces (no tabs). Use four spaces for each level of indentation.
  • Prefer vertical scrolling to horizontal scrolling. If necessary to avoid long lines, method parameters, throws lists, etc. should be listed one per line (horizontally aligned so that they all start in the same column). Lines longer than 120 characters should be avoided if at all possible.
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.