Re: style guide on method ordering
Rex Mottram wrote:
But even beyond accessors, there are questions wrt static methods,
constructors, toString(), etc. I've been tending toward something like
<static constants>
<static methods>
<private instance data>
<constructors>
<accessors>
<utility methods>
<standard interface methods>
<toString and friends>
It all depends. I always try to put "main" first, if present. Top down
is a good thing, even today.
Private instance fields is a tough call. I like to put my constructors
first, if possible, but many folks are used to seeing variable
definitions up top. It's a judgment call.
Ditto with static final constants. If the final variable is only used
with some methods, it might go next to them. Otherwise, it's a
candidate for being up top, just because many people expect it there.
Note that some auto-code generators put generated private fields last.
This is against code guidelines, but it works. They're generated
fields, you don't really want to be bothered by them, so they go at the
end of the class definition.
Static methods by default go last for me, not first. But it's better to
group them with similar function. A static "newInstance" method goes
with the constructors.
Don't be afraid to break all the rules if it makes a given class
definition more clear.