Differences between revisions 1 and 9 (spanning 8 versions)
Revision 1 as of 2005-02-11 02:10:20
Size: 1403
Comment:
Revision 9 as of 2008-01-01 01:47:38
Size: 2512
Comment:
Deletions are marked like this. Additions are marked like this.
Line 1: Line 1:
== Coding Standards for Java Code in Jython ==
When in doubt follow the Sun Java standards:
When contributing code or patches to Jython, please try to follow these guidelines.
Line 4: Line 3:
http://java.sun.com/docs/codeconv/ == Python Code ==
In general, follow [http://www.python.org/dev/peps/pep-0008/ PEP 8]. When importing Java code, always use fully qualified class names, not package names ie from java.lang import String instead of from java import lang.
Line 6: Line 6:
=== Example === == Java Code ==
 * Javadoc on any publicly exposed method or field.
 * 4 spaces for indentation, no tabs.
 * No nested ternary statements.
 * A luxurious 100 characters per line.
 * No copy and pasted, repeated code: if you're doing the same thing twice, make a method.
 * Braces on all loops and if else statements
 * A space an if and its parenthesis ie `if (` instead of `if(`.
 * Methods longer than 10 lines should have whitespace and comments breaking them up into coherent operations.
 * Descriptive names for fields and methods.
 * No `@author` tags in code.
 * Any field on an object that isn't modified after construction should be final.
 * Fields at the top of the class.
 * Don't declare fields with their default values ie `private Object blah;` instead of `private Object blah = null;` and `int i;` instead of `int i = 0;`

Beyond these rules, follow the [http://java.sun.com/docs/codeconv/ Sun Java standards].

=== Example (adapted from Sun document) ===
Line 8: Line 25:
Line 10: Line 26:
Line 12: Line 27:
Line 15: Line 29:
 * @author Firstname Lastname
Line 19: Line 32:
Line 22: Line 34:

/** 
    /**
Line 28: Line 39:
Line 31: Line 41:
Line 34: Line 43:
Line 37: Line 45:

/** 
    /**
Line 44: Line 51:
Line 49: Line 55:
        // ...implementation goes here...          // ...implementation goes here...
Line 51: Line 57:
Line 57: Line 62:
        // ...implementation goes here...          // ...implementation goes here...
Line 60: Line 65:
}}}  }}}

When contributing code or patches to Jython, please try to follow these guidelines.

Python Code

In general, follow [http://www.python.org/dev/peps/pep-0008/ PEP 8]. When importing Java code, always use fully qualified class names, not package names ie from java.lang import String instead of from java import lang.

Java Code

  • Javadoc on any publicly exposed method or field.
  • 4 spaces for indentation, no tabs.
  • No nested ternary statements.
  • A luxurious 100 characters per line.
  • No copy and pasted, repeated code: if you're doing the same thing twice, make a method.
  • Braces on all loops and if else statements
  • A space an if and its parenthesis ie if ( instead of if(.

  • Methods longer than 10 lines should have whitespace and comments breaking them up into coherent operations.
  • Descriptive names for fields and methods.
  • No @author tags in code.

  • Any field on an object that isn't modified after construction should be final.
  • Fields at the top of the class.
  • Don't declare fields with their default values ie private Object blah; instead of private Object blah = null; and int i; instead of int i = 0;

Beyond these rules, follow the [http://java.sun.com/docs/codeconv/ Sun Java standards].

Example (adapted from Sun document)

package org.jython.blah;
import org.jython.blah.BlahBlah;
/**
 * Class description goes here.
 */
public class Blah extends SomeClass {
    /* A class implementation comment can go here. */
    /** classVar1 documentation comment */
    public static int classVar1;
    /**
     * classVar2 documentation comment that happens to be
     * more than one line long
     */
    private static Object classVar2;
    /** instanceVar1 documentation comment */
    public Object instanceVar1;
    /** instanceVar2 documentation comment */
    protected int instanceVar2;
    /** instanceVar3 documentation comment */
    private Object[] instanceVar3;
    /**
     * ...constructor Blah documentation comment...
     */
    public Blah() {
        // ...implementation goes here...
    }
    /**
     * ...method doSomething documentation comment...
     */
    public void doSomething() {
        // ...implementation goes here...
    }
    /**
     * ...method doSomethingElse documentation comment...
     * @param someParam description
     */
    public void doSomethingElse(Object someParam) {
        // ...implementation goes here...
    }
}

CodingStandards (last edited 2018-03-31 19:06:54 by JeffAllen)