Code Conventions

Code Conventions

Following the lead of well established projects such as Apache and Eclipse, all code in CAS3 will comply with the Code Conventions for the Java and additionally with the CAS3 specific conventions listed below. Javadoc should exist on all publicly exported class members [Bloch, 2001] and follow the How to Write Doc Comments for the Javadoc Tool style guide.

CAS3 Specific Code Conventions

Brackets

All brackets should appear in compact form and are mandatory even for single line statements.

public class FooClass {
    public void BarMethod() {
        if (...) {
            // single line statement
        }
    }
}

Needless else clauses

We do not use needless else clauses. We would write:

public class FooClass {
    public String BarMethod() {
        if (...) {
            return "foo";
        }
        
        return bar;

    }
}

rather than

public class FooClass {
    public String BarMethod() {
        if (...) {
            return "foo";
        } else {
            return "foobar";
        }
    }
}

Indentations

Code indentation should be set to use 4 spaces. Tabs should never be used for indentation.

Commons Logging

We use Commons Logging. In the case where we are extending an abstract class someone else provided for us, and if they were so kind as to provide a protected Log instance for the runtime class, we'll try to use that. In the case where we create our own Log instance, we will name it "log".

Qualifying instance variables with "this"

We qualify all instance variables with "this" with the exception of the Commons Logging instance (named "log" or "logger"). We don't qualify that variable with "this" because it is well-known to be threadsafe. log.warn("Message") becomes more idiom than invocation of instance variable.

Use of the final keyword.

We use the keyword "final" wherever we can, because it is probably a good idea.

Naming testcases

If we were writing a JUnit testcase extending junit.framework.TestCase for code defined in Foo.java, we would name it FooTests.java . We do not allow any code which is not a testcase extending junit.framework.TestCase to have a name ending in "Tests".

Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.