|
Coding Guidelines
Diva tries to take a non-controversial approach to coding guidelines. We treat guidelines as guidelines, not
as commandments. Below are the conventions that we have adopted, and which we like to see in code that is part
of Diva. As usual, the best guide is the existing code. There are many other sources of guidelines, here are a
couple of good ones:
Java Code Conventions
Doug Lea's guidelines
Conventions
Here are the key conventions we have adopted in Diva:
Reminders
Here are a few reminders of accepted Java coding conventions, just in case you have forgotten them :-)
- Methods that return an Iterator are named as the plural of the thing they return. For example,
public Enumeration elements () {
...
}
- Use "set" and "get" in names of methods that set and return a property-like value. For
example,
public FooBar getFooBar ();
public void setFooBar (FooBar f);
If the type is boolean, use "set" and "is":
public boolean isVisible ();
public void setVisible (boolean flag);
- Static constants are uppercase. (Sun doesn't consistently follow this convention themselves.) For example,
public static int LARGER_THAN_LIFE;
Recommendations
Here are some recommendations for things that we have found to make our lives easier:
|