August, 2018
It is notoriously difficult to create a coding standard that satisfies all developers, let alone create one that is actually adhered to. Nonetheless, there is an ArtiSynth coding standard which all contributors are encouraged to follow.
The standard is similar in appearance to the coding rules provided by Sun, although it does differ slightly. For users of Eclipse, there is an code style file located in
$ARTISYNTH_HOME/support/eclipse/artisynthCodeFormat.xml
that supports most of the conventions, though not all, as noted below.
As with the Sun coding rules, all braces are cuddled. Basic indentation is set to 3 to keep code from creeping too far across that page. For example:
As in the Sun rules, code following control constructs is always enclosed in a braced block, even when this is not necessary. That means that
should be used instead of
The reason for this is to provide greater uniformity and to make it easier to add and remove statements from the blocks.
Code should be indented with spaces only. Tabs should not be used since the spacing associated with tabs varies too much between coding environments and can not always be controlled.
Again, as with the Sun rules, code should be kept to 80 columns. The idea here is that it is easier to read code that doesn’t creep too far across the page. However, to maintain an 80 column width, it will often be necessary to wrap lines.
If breaking a line is necessary, the beginning of an argument list is a good place to do it. The break should be indented by the usual 3 spaces. The result can look at bit like Lisp:
If at all possible, do not break lines at the ’.’ used for method or field references. For clarity, it is better to keep these together with their objects. Therefore, please *do not* do this:
Note that Eclipse will not generally enforce these breaking conventions, so you need to do this yourself.
Another good place for a line break is after an assignment operator, particularly if the left side is long:
Again, Eclipse will not generally enforce this, so it must be done manually.
When line wrapping is used inside a conditional expression, the expression itself should be aligned with the opening parentheses, with operators placed at the right:
Again, note the Eclipse will not generally enforce this, and will instead tend to produce output like this:
No spaces are placed before empty argument lists, as in
This is largely to improve readability, particularly when accessors are chained together in a single statement.