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

Compare with Current View Page History

« Previous Version 2 Next »

${renderedContent}

Quick Links to:

The SAIS Framework generally follows the code conventions set by the Java programming language that can be found at http://java.sun.com/docs/codeconv/html/CodeConvTOC.doc.html

For the purposes of this document, we'll highlight those areas that seem to be most frequently overlooked, and ways in which we might deviate from the standard.

Line Length

Java specifies a line length of 80 characters "since they're not handled well by many terminals and tools."  We find this limitation to be a little outdated.  Modern screens and development environments can easily accommodate many more characters than 80, and limiting to 80 makes code especially unreadable.

Class and Interface Declarations

When coding Java classes and interfaces, the following formatting rules should be followed:

  • No space between a method name and the parenthesis "(" starting its parameter list
  • Open brace appears at the end of the same line as the declaration statement
  • Closing brace starts a line by itself indented to match its corresponding opening statement, except when it is a null statement the "}" should appear immediately after the "{"
  • Methods are separated by a blank line

E.g.,

class Sample extends Object {
    int ivar1;
    int ivar2;

    Sample(int i, int j) {
        ivar1 = i;
        ivar2 = j;
    }

    int emptyMethod() {}

    ...
}

if, if-else, if else-if else Statements

The if-else class of statements should have the following form:

if (condition) {
    statements;
}

if (condition) {
    statements;
}
else {
    statements;
}

if (condition) {
    statements;
}
else if (condition) {
    statements;
}
else {
    statements;
}

do-while Statements

A do-while statement should have the following form:

do {
    statements;
}
while (condition);

try-catch Statements

A try-catch statement should have the following format:



try {    statements;
}
catch (ExceptionClass e) {
    statements;
}

A try-catch statement may also be followed by finally, which executes regardless of whether or not the try block has completed successfully.

try {
    statements;
}
catch (ExceptionClass e) {
    statements;
}
finally {
    statements;
}
  • No labels