Skip to content

Contribution Guidelines

Joshua Hertlein edited this page Oct 10, 2013 · 1 revision

Coding Standards

General

In general, adhere strictly to Oracle's guidelines for Java. There are, however, a few exceptions.

Line Wrapping & Line Length

As you've probably noticed, this is no longer the year 1985. It is very common for editors to have the capacity to display more than 80 columns. As such, you should not line-wrap code at 80 columns. If it gets ridiculously long (substantial side-scrolling is needed to view end of line), line wrap at your convenience, but unless it really is that long of a line, don't wrap it.

Opening Delimiters

Use K&R or "Egyptian"-style delimiter placement. i.e.

public String snafucate(String s) {
    //snafucate the String
    return s;
}

Declaring many variables of the same type

This isn't a hard and fast rule, but I find that this

public static final int SNAFUCATION_THRESHOLD = 1, SNAFUCATION_BIT_SHIFT_COUNT = 16, SNAFUCATION_MULTIPLIER = 9001;

is a little prettier when written as

public static final int 
                        SNAFUCATION_THRESHOLD = 1, 
                        SNAFUCATION_BIT_SHIFT_COUNT = 16, 
                        SNAFUCATION_MULTIPLIER = 9001;

Identifier Lengths

As I mentioned before, this is no longer the year 1985. As such, our compilers can handle identifiers longer than 6 characters and our IDEs can offer auto-completion of longer identifiers. With this in mind, I find that I prefer identifiers be longer and more descriptive rather than terser but a little more vague. By all means, keep using i as an index for for loops and o for arbitrary Objects. However, perhaps int count is potentially better written as numSnafucatedStringsCount? You can still just type num and then hit CTRL+SPACE (in Netbeans) to get it autocompleted to the full identifier.

This produces code that documents itself much better, at the cost of only two extra keystrokes.

Nesting Anonymous Classes

Don't go more than one level deep unless you have a really good reason to. Nesting anonymous classes is probably the easiest way to write completely unreadable code in Java. If you're writing an anonymous Runnable subclass and want to make an anonymous Collection subclass to get an initialization block, go ahead. But don't let it go further than that.

Clone this wiki locally