DEV Community

Discussion on: How do you decide what order to put code in?

Collapse
 
val_baca profile image
Valentin Baca • Edited

for java classes, this is a rough outline, but it's not very strictly enforced.

public class Foobar {
    // public static final constants
    // private static final constants
    // private fields
    //
    // public static methods (usually means there are no constructors)
    //
    // constructors
    //
    // public methodAA
    // private methodXX that *only* methodAA calls
    //
    // public methodBB
    // private methodYY that *only* methodBB calls
    //
    // (and so on...)
    //
    // private static methods (usually validation)
    //
    // private methods used by several methods
}

public methods should probably be in alphabetical order, but not important at all.

I personally really dislike "section header" comments, since they do very little. I can tell where the private methods are because they say private. I really dislike seeing:

/**************PRIVATE METHODS**********************/

Two line breaks between "sections" is more than enough to indicate a new "code paragraph"