Skip to content
This repository has been archived by the owner on Feb 1, 2020. It is now read-only.

Style Guidelines

dwightguth edited this page Apr 11, 2014 · 6 revisions

Syntax

  1. No tabs. All indents should be four spaces.
  2. No line should be longer than 99 characters, except import statements, which should be one per line.
  3. Java code must declare the package it is part of.
  4. Imports should not be present unless they are used in the file.
  5. import foo.* should be used sparingly, only when it improves code readability.
  6. Imports should be used whenever a qualified path is required, except in the case of namespace conflicts.
  7. long literals shall be declared with an uppercase "L".
  8. There shall be one outer type per file, named the same as the filename.
  9. Text files shall end in a new line character.

Code Structure

  1. Code should not follow the pattern if (something) { return true; } else { return false; } or other similar patterns.
  2. Comparison of a String literal to a String object reference should follow the pattern "foo".equals(bar);

Documentation

  1. In interfaces, all methods and the declaration itself should be javadoc'd.
  2. In enums, all enum values and the declaration itself should be javadoc'd.
  3. In classes, fields which have complex meaning, or methods which perform complex tasks, should be javadoc'd, as should the class itself.

Copyright

Copyright notices shall be present in all files, and kept up to date. For example, in Java classes, the first line of any file which was created in 2012 and last modified in 2014 should be:

// Copyright (C) 2012-2014 K Team. All Rights Reserved.

The copyright notice is whitespace and capitalization sensitive. Whenever modifying a file, the copyright notice should be updated to end with the current year. This will be accomplished by means of periodic changes to the checkstyle xml file every January 1.

For information on the precise syntax of copyright notices in other languages, please refer to the checkstyle specification