You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@geronimo.apache.org by Alex Blewitt <Al...@ioshq.com> on 2003/08/13 14:40:41 UTC

Suggested coding convention: sort methods

One coding convention I've used in the past is sorting the contents of 
a file into alphabetical order. Some may argue that it makes it easier 
to find things; some may not care. A few of you will probably say it 
makes it worse :-)

One good thing about such a standard is that it is a standard that can 
be followed (and/or applied automatically to existing code). In much 
the same way that everyone working on a common coding convention will 
find things easier if everyone does it, the same can also apply to 
sorting the members.

Eclipse provides a way of configuring the sort orders as follows:

static fields (*)
static initialisers
static methods
instance fields
instance initialiser
constructors
instance methods

A nice property of a sorted file when using a source code control 
system that diffs is that diffs between two sorted files are likely to 
be the smallest possible (and perhaps, easier to merge when conflicts 
occur).

Of course, I suspect that many people will not be using Eclipse (or one 
that doesn't offer such sorting functionality) so perhaps this should 
be a recommendation rather than a standard, but if people think that it 
will make sense then we can work towards it. And it means if you add a 
few methods, trying to put them in the right 'sorted' place will then 
help.

What do people think?

flameSuit.setEnabled(true)


Re: Suggested coding convention: sort methods

Posted by Mark Mahieu <ma...@twistedbanana.demon.co.uk>.
The real can of worms is opened when developers start reformatting code 
with Pretty Printers or IDEs and then try to get their patches applied; 
everything is suddenly out of sync with what's in CVS.  Even 
automatically enforcing the style as it gets checked in doesn't really 
avoid that one.

I'm sure I could find some earlier, er, 'discussions' about this in the 
archives of other mailing lists for everyone's amusement ;-)

For what it's worth, I'm +1 on the general idea though.

Mark


Re: Suggested coding convention: sort methods

Posted by Jason Dillon <ja...@coredevelopers.net>.
I would rather see us order by functional group.  If a public uses a 
protected or private then I would expect to find that method near where 
it is used.

IMO artificial grouping based on method name or accessibility is silly.

--jason


On Wednesday, August 13, 2003, at 07:40  PM, Alex Blewitt wrote:

> One coding convention I've used in the past is sorting the contents of 
> a file into alphabetical order. Some may argue that it makes it easier 
> to find things; some may not care. A few of you will probably say it 
> makes it worse :-)
>
> One good thing about such a standard is that it is a standard that can 
> be followed (and/or applied automatically to existing code). In much 
> the same way that everyone working on a common coding convention will 
> find things easier if everyone does it, the same can also apply to 
> sorting the members.
>
> Eclipse provides a way of configuring the sort orders as follows:
>
> static fields (*)
> static initialisers
> static methods
> instance fields
> instance initialiser
> constructors
> instance methods
>
> A nice property of a sorted file when using a source code control 
> system that diffs is that diffs between two sorted files are likely to 
> be the smallest possible (and perhaps, easier to merge when conflicts 
> occur).
>
> Of course, I suspect that many people will not be using Eclipse (or 
> one that doesn't offer such sorting functionality) so perhaps this 
> should be a recommendation rather than a standard, but if people think 
> that it will make sense then we can work towards it. And it means if 
> you add a few methods, trying to put them in the right 'sorted' place 
> will then help.
>
> What do people think?
>
> flameSuit.setEnabled(true)
>