Coding Standards

We follow Oracle/Suns best practices in coding when possible. Much of below is either a rehash, or a coding style we want to follow.

Names and Cases

Generic

  • Names are descriptive

  • Words get capitals, not sounds in the word. String chromoSomes is wrong.

Java

  • variablesAndMethods are camelCase.

  • ClassesAreLargeCamelCase

  • CONSTANTS_ARE_LIKE_THIS (THAT_INCLUDES_YOU,ENUMS)

Return statements

Languages with methods

  • returns only return primitives or simple method calls..

  • Return statements should be on their own line.

if(x)return bob; is not fine. Replace with: if(x){    return bob; }
  • Multiple returns are okay.

Java Examples

  • return obj; is fine. 

  • return doIt(bob); is fine;

  • return 1-Math.abs(bob); is not fine.

  • return this.super.steveThis(mary, sue, null, (String[])null) is really not fine.

Ownership

  • All classes should have an author tag.

Java Examples

  • Author tags look like this : @author jdl232  Josh L.S.

Note:  @author <userid> is mandatory, name is optional and placed afterwards. UserId is your netid, rhodes server id, or gobii id. (We try to keep these mostly the same: notable exception @KevinPalis ).

  • If you've performed a major revision of the code, you may want to add your name to the author tag. Javadocs works just fine with multiple author tags, just place yours after theirs, and add a comment below your author tag.

/** *@author kpalis *@author jdl232 Josh L.S. * Added doIt(), bar() and baz() methods. Refactored everything. */
  • If you want to sign a comment so readers know it's you, you can use just your id tag.

return simple(x);//Took out complex return logic -jdl232

Extras

  • Break complicated lines into multiple lines. There is no charge for whitespace, and it improves readability to slow down.

  • Globals are not okay. God Objects are slightly preferred, but Singletons are more preferred.

  • Classes should contain logical chunks of code. Eclipse has a 'Refactor' right click for a reason.