This document describes a list of coding conventions that are required for code submissions to the project. By default, the coding conventions for most Open Source Projects should follow the existing coding conventions in the code that you are working on. For example, if the bracket is on the line after the if statement, then you should write all your code to have that convention.
Below is a list of coding conventions that are specific to the Raccoon Framework. Anything else not specificially mentioned here should follow the official Sun Java Coding Conventions
All brackets (class, method, if, try, etc) must begin start at the end of line and end on a new line. Example :
public class SomeClass { public void someMethod() { if (xxx) { } } }
Brackets are mandatory, even for single line statements !
/** Incorrect */ if (expression) /** some code */ /** Correct */ if (expression) { /** some code */ }
keywords followed by a parenthesis should be separated by a space. Example :
while (true) { /** some code */ }
Blank space should appear after commas in argument lists. Binary operators should be separated from their operands by spaces :
a += c + d; a = (a + b) / (c * d); while (d++ = s++) { n++; } printSize("size is " + foo + "\n");
2 spaces. NO tabs Period. We understand that a lot of you like to use tabs, but the fact of the matter is that in a distributed development environment, when the cvs commit messages get sent to a mailing list, they are almost impossible to read if you use tabs.
Javadoc SHOULD exist on all your class members (methods + class variables), including the private ones. Also, if you are working on existing code and there currently isn't a javadoc for that method/class/variable or whatever, then you should contribute and add it. This will improve the project as a whole.
Also add code comments when you think it's necessary (like assumptions), especially when the code is not obvious.
Note: Comments should be multiple line enabled
/** Some comment */
and not
// Some comment
The Raccoon Framework License MUST be placed at the top of each and every file.
If you contribute to a file (code or documentation), add yourself to the top of the file (below the existing authors). For java files the preferred Javadoc format is:
@author <a href="mailto:user@domain.com">John Doe</a>
Class variables should bear the prefix 'm' if they aren't static and should preferably be referenced using the
this
object. Example :
public class SomeClass { private String mSomeString; [...] public void someMethod() { logger.debug("Value = " + this.mSomeString); } }
Method parameters should be prefixed with a 'p'. For example :
public void someMethod(String pClassName) { }
Avoid lines beyond 80 characters for Code, comments, ... the maximum line length is 120 chars.
All .java files should have a
@version
tag like the one below.
@version $Id: TestJavaToMessage.java,v 1.3 2003/07/01 19:21:26 crouvrais Exp $
All
import
statements should containing the full class name of classes to import and should
not use the
"*"
notation. Package imports aren't accepted.
An example:
/** Correct */ import java.util.Date; import java.net.HttpURLConnection; /** Not correct */ import java.util.*; import java.net.*;