You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 5 Next »

Java Coding Conventions for org.lcsim

Indentation

Please use 4 spaces per tab.

Setup your Java Indentation settings in Netbeans like this.

Naming

In general, abbreviations should not be used in naming.

Method Names

Methods should be named with a verb and a noun. The verb should be capitalized.

Please do not use underscores in Java names.

Here are examples of good method names.

computeSum()
getX()
setY()

Getters should start with get and setters should start with set. Method names
such as x() instead of getX() are ambiguous.

Variable Names

Variables should start with a lowercase letter. Subsequent words should be capitalized.

Here are examples of variable names.

thetaIndex
phiBins
binValues

No distinction is made between local variables and member variables as far as naming conventions.
To disambiguate local and member variables, use the this keyword.

For instance, this is a perfectly valid way of assigning a member variable that has the same name
as the method argument.

void setFoo(int foo)
{
    this.foo = foo;
}

Interfaces and Implementations

Java makes a distinction between interfaces, which have no method bodies, and implementations.

In general, the interface should have the "natural" name. For instance, an interface could be
called Identifier, while the implementation should have a suffix such as Basic, Base or
Impl. Even better is to separate the implementations into a subpackage such as org.lcsim.ids.impl.

  • No labels