In order to facilitate the human reading of FOP source code, the FOP developers have agreed on a set of coding conventions. The basis of these coding conventions is documented in the Apache XML Project Guidelines, which requires that all Java Language source code in the repository must be written in conformance to Sun's Code Conventions for the Java Programming Language. In addition, the FOP developers have agreed to other conventions, which are summarized in the following table:
Convention | Rationale | Enforced By |
---|---|---|
Every Java source file starts with the Apache licence header. | Required by Apache. | checkstyle |
No tabs in content | Programmers should not have to adjust the tab settings in their editor to be able to read the source code. | checkstyle |
Indentation of 4 spaces per level | Maximize readability. | Not enforced |
Comments must be in English | To avoid the need for everyone to learn all languages, English has become the standard language for many technology projects, and is the only human language that all FOP developers are expected to know. | Not enforced |
Fully qualify all import statements (no "import java.util.*") | Clarity | checkstyle |
No underscores in variable names except for static finals. | Upper/lower case distinctions can be made in all other variable names, eliminating the need for artificial word boundaries. | checkstyle |
Opening brace for a block should be on the same line as its control statement (if, while, etc.). | Standardization, general preference. | checkstyle |
For developers that dislike these conventions, one workaround is to develop using their own style, then use a formatting tool like astyle (Artistic Style) before committing.
The java syntax checker "
To use the "checkstyle" target in FOP's build process, download the source from the
Checkstyle is probably most useful when integrated into your IDE. See the Checkstyle web site for more information about IDE plugins.
The following general principles are a distillation of best practice expectations on the FOP project.