Coding style

Here are some best practices that are recommended by Judgels maintainers.

Java

  1. Use 4 spaces for indentation (not tabs).

  2. Use curly braces in a block even it contains only one statement.

  3. Put the opening curly brace on the right of the statement:

    if (condition) {
        //
    }
    
  4. Do not use star import (import xxx.*;). Import individual classes.

  5. Mark classes as final whenever possible.

  6. Use Google Guava’s immutable collection whenever possible.

  7. Make classes immutable whenever possible. Do not introduce setters unless really required. Initialize the class properties inside the constructor.

  8. Prefer this:

    public void someFunction() {
        if (!requiredCondition1) {
            return failureMethod1();
        }
    
        if (!requiredCondition2) {
            return failureMethod2();
        }
    
        // main function code
    
    }
    

    to:

    public void someFunction() {
        if (requiredCondition1) {
            if (requiredCondition2) {
    
                // main function code
    
            } else {
                return failureMethod2();
            }
        } else {
            return failureMethod1();
        }
    }
    
  9. Put only statements that can really throws exception, inside a try-block. Pull the ones that don’t outside.