HomeSF Project Home

Gridarta Development Documentation: Code Conventions

This document describes the Code Conventions used for Gridarta.

Code Conventions for the JavaTM Programming Language

Additionally, the following set of rules applies:

Small Rules

("small" in the sense how long it takes to describe them, not in their importance!)

Field Initialization

Field initialization with the automatic default value is only allowed if the automatic default value carries semantics that are used later. In all other circumstances, which means in most cases, fields must not be initialized with the automatic default value. (The automatic default value is null, zero (any mutations of 0 resp. 0.0) or false.)

Stream I/O Handling

The following example code shows how streams should be opened / closed:

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

public class SafeCopy {
   
public static void main(final String... args) {
       
try {
           
final InputStream in = new FileInputStream(args[0]);
           
try {
               
final OutputStream out = new FileOutputStream(args[1]);
               
try {
                   
final byte[] buf = new byte[4096];
                   
for (int bytesRead; (bytesRead = in.read(buf)) != -1;) {
                       
out.write(buf, 0, bytesRead);
                   
}
                }
finally {
                   
out.close();
               
}
            }
finally {
               
in.close();
           
}
        }
catch (final IOException e) {
           
System.err.println(e);
       
}
    }
}

Rationale:

The single catch for multiple streams is okay because the following cases can happen:

The Rules in Detail

This description describes the inspection profile "No errors allowed here". As the name already suggests, this inspection profile must always run without errors. The purpose of this inspection profile is to prevent a regression of code quality. Currently it is quite small. New rules will be added whenever a certain level of cleanness and style is reached.

The following list explains the current rules, listed in a way that you can easily identify them in IntelliJ IDEA. It serves two purposes. One is to explain the rationale of the configured rules. The other is to enable developers that do not use IntelliJ IDEA / InspectionGadgets to know what the rules are to be able to perform the same verifications.

SourceForge.net LogoSupport This Projectfreshmeat.netValid HTML 4.01!Valid CSS! Feedback: webmaster
$Date: 2008-05-31 23:48:40 +0200 (Sa, 31 Mai 2008) $