Project specific coding conventions
1. Brackets
All brackets (class, method, if, try, etc) must begin 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
}
2. Blank Spaces
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");
3. Indentations
4 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.
4. Comments
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.
5. Author references
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 devnickname
7. Class variables
Class variables should not have any prefix and must be referenced using the this object. Example :
public class SomeClass
{
private String someString;
[...]
public void someMethod()
{
logger.debug("Value = " + this.someString);
}
}
8. Parameter names
Method parameters should not have any prefix. For example :
public void someMethod(String className)
{
}
本文介绍了Java项目特定的编码规范,涵盖括号使用、空格、缩进、注释、作者引用、类变量、参数命名、行长度、版本控制和导入语句等方面。如括号需另起一行,注释应使用Javadoc,行长度避免超120字符等。

2429

被折叠的 条评论
为什么被折叠?



