Project Specific Coding Conventions

zhaozj2021-02-16  106

Project Specific Coding Conventions

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 shouth be separated by a space. EXAMPLE:

While (True)

{

// Some Code

}

BLANK SPAULD 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 is not a javadoc for that method / class / variable or whatever, then you should Contribute and add it. this will ign the project as a..

Also Add Code Comments When You Think It's Necessary (Like Assumption), 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 VariableSclass Variables Should Not Have Any Prefix and Must Be Reference Using The this Object. EXAMPLE:

Public Class SomeClass

{

PRIVATE STRING SOMEString;

[...]

Public void someMethod ()

{

Logger.debug ("Value =" this.somSomSomSomSomSomSomstring);

}

}

8. Parameter Names

Method Parameters Should Not Have Any Prefix. For example:

Public void SomeMethod (String ClassName)

{

}

9. LINE Length

Avoid Lines Longer Than 120 Characters for Code, Comments, ...

10. Versioning

All.java files shouth .java files shouth. @Version tag like the one below.

@version $ revision $ ($ Author $)

11. Qualified Imports

All import statements shop contact the full class name of classes to import and shop not use the "*" NOTATION:

AN EXAMPLE:

// Correct

Import java.util.date;

Import java.net.httpurlConnection;

// Not Correct

Import java.util. *;

Import java.net. *;

转载请注明原文地址:https://www.9cbs.com/read-10419.html

New Post(0)