[Geoserver-devel] code formatting and conventions

Hi guys,

It is a long time since I'm noticing an increasing loose of care on applying the code formatting we're supposed to. Not to mention tabs instead of spaces for indentation, lack of (c) headers, and even small but bothering breaks of the code conventions, like lack of braces in if statements. And also unused imports..

Question is, is this deliberate? I bet not and would like to encourage all developers to systematically apply the formatting and follow conventions as described in <http://geoserver.org/display/GEOSDOC/1+Code+Conventions&gt;\.

As we all use eclipse and the formatter is there please just try to get used to press CTRL+ALT+F for formatting and CTRL+ALT+O for imports clean up... please?

Cheers,

Gabriel

I am actually sort of against mass formatting changes, as it usually ends up being more trouble than its worth. It also makes it really hard to apply patches among multiple branches.

That said, I don;t think that is what you are proposing. I would be a big +1 for enforcing more strictly code conventions via peer review. Or even if we could run a tool that would check for infractions. However that would probably require us to do a mass reformatting.

2c.

Gabriel Roldan wrote:

Hi guys,

It is a long time since I'm noticing an increasing loose of care on applying the code formatting we're supposed to. Not to mention tabs instead of spaces for indentation, lack of (c) headers, and even small but bothering breaks of the code conventions, like lack of braces in if statements. And also unused imports..

Question is, is this deliberate? I bet not and would like to encourage all developers to systematically apply the formatting and follow conventions as described in <http://geoserver.org/display/GEOSDOC/1+Code+Conventions&gt;\.

As we all use eclipse and the formatter is there please just try to get used to press CTRL+ALT+F for formatting and CTRL+ALT+O for imports clean up... please?

Cheers,

Gabriel

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day trial. Simplify your report design, integration and deployment - and focus on what you do best, core application coding. Discover what's new with Crystal Reports now. http://p.sf.net/sfu/bobj-july
_______________________________________________
Geoserver-devel mailing list
Geoserver-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geoserver-devel

--
Justin Deoliveira
OpenGeo - http://opengeo.org
Enterprise support for open source geospatial.

Justin Deoliveira wrote:

I am actually sort of against mass formatting changes, as it usually ends up being more trouble than its worth. It also makes it really hard to apply patches among multiple branches.

concern shared. But for all means I mean it to try to keep it clean for new classes and patches, etc.
As an example, the new UI is not affected by backwards patching conflicts as it's a whole new thing, so that's perhaps _the_ one I would like to mass format, and as said keep an eye on any new code. Hope that makes more sense?

That said, I don;t think that is what you are proposing. I would be a big +1 for enforcing more strictly code conventions via peer review. Or even if we could run a tool that would check for infractions. However that would probably require us to do a mass reformatting.

2c.

Gabriel Roldan wrote:

Hi guys,

It is a long time since I'm noticing an increasing loose of care on applying the code formatting we're supposed to. Not to mention tabs instead of spaces for indentation, lack of (c) headers, and even small but bothering breaks of the code conventions, like lack of braces in if statements. And also unused imports..

Question is, is this deliberate? I bet not and would like to encourage all developers to systematically apply the formatting and follow conventions as described in <http://geoserver.org/display/GEOSDOC/1+Code+Conventions&gt;\.

As we all use eclipse and the formatter is there please just try to get used to press CTRL+ALT+F for formatting and CTRL+ALT+O for imports clean up... please?

Cheers,

Gabriel

------------------------------------------------------------------------------

Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day trial. Simplify your report design, integration and deployment - and focus on what you do best, core application coding. Discover what's new with Crystal Reports now. http://p.sf.net/sfu/bobj-july
_______________________________________________
Geoserver-devel mailing list
Geoserver-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geoserver-devel

Gabriel Roldan wrote:

Justin Deoliveira wrote:

I am actually sort of against mass formatting changes, as it usually ends up being more trouble than its worth. It also makes it really hard to apply patches among multiple branches.

concern shared. But for all means I mean it to try to keep it clean for new classes and patches, etc.
As an example, the new UI is not affected by backwards patching conflicts as it's a whole new thing, so that's perhaps _the_ one I would like to mass format, and as said keep an eye on any new code. Hope that makes more sense?

It does... but any mass format basically kills any ability to do svn blame. Which I think is pretty important. For instance when finding a line of code that has a problem it is nice to know if I was the one who wrote it originally, or it is someone else that i need to talk to about it.

That said, I don;t think that is what you are proposing. I would be a big +1 for enforcing more strictly code conventions via peer review. Or even if we could run a tool that would check for infractions. However that would probably require us to do a mass reformatting.

2c.

Gabriel Roldan wrote:

Hi guys,

It is a long time since I'm noticing an increasing loose of care on applying the code formatting we're supposed to. Not to mention tabs instead of spaces for indentation, lack of (c) headers, and even small but bothering breaks of the code conventions, like lack of braces in if statements. And also unused imports..

Question is, is this deliberate? I bet not and would like to encourage all developers to systematically apply the formatting and follow conventions as described in <http://geoserver.org/display/GEOSDOC/1+Code+Conventions&gt;\.

As we all use eclipse and the formatter is there please just try to get used to press CTRL+ALT+F for formatting and CTRL+ALT+O for imports clean up... please?

Cheers,

Gabriel

------------------------------------------------------------------------------

Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day trial. Simplify your report design, integration and deployment - and focus on what you do best, core application coding. Discover what's new with Crystal Reports now. http://p.sf.net/sfu/bobj-july
_______________________________________________
Geoserver-devel mailing list
Geoserver-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geoserver-devel

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day trial. Simplify your report design, integration and deployment - and focus on what you do best, core application coding. Discover what's new with Crystal Reports now. http://p.sf.net/sfu/bobj-july
_______________________________________________
Geoserver-devel mailing list
Geoserver-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geoserver-devel

--
Justin Deoliveira
OpenGeo - http://opengeo.org
Enterprise support for open source geospatial.

Gabriel Roldan ha scritto:

Hi guys,

It is a long time since I'm noticing an increasing loose of care on applying the code formatting we're supposed to. Not to mention tabs instead of spaces for indentation, lack of (c) headers, and even small but bothering breaks of the code conventions, like lack of braces in if statements. And also unused imports..

Agreed, that's annoying (quite a bit of the tabs are my fault, when
I switched to Linux I forgot to setup again the GeoTools code convention).

As for lack of braces, can you confirm that's part of the Sun Java
coding convention? I really hate to add extra braces if not necessary,
to me:

if(xxx)
   // one liner

reads much better than

if(xxx) {
   // one liner
}

Our Eclipse formatter does not turn the first form into the second,
so I guess it is actually not part of the convention (either that
or the template is incomplete)

One thing that is annoying me instead is adding spaces in function calls, something like, f( a, b ) instead of f(a,b).
I don't know if the coding convention covers it, for sure the
Ecilpse formatter turns the first form into the latter.

Question is, is this deliberate? I bet not and would like to encourage all developers to systematically apply the formatting and follow conventions as described in <http://geoserver.org/display/GEOSDOC/1+Code+Conventions&gt;\.

As we all use eclipse and the formatter is there please just try to get used to press CTRL+ALT+F for formatting and CTRL+ALT+O for imports clean up... please?

Hmmm... I always clean imports, but never user CTRL-ALT-F because it
mixes together real changes with formatting ones.
If a file is really screwed up, I'd suggest to format it in both
branches (formatting just one is murder, makes porting patches
a nightmare) and make the commit a pure formatting one (no other changes).

Ideally we could mass reformat the code in a moment where there
is just one active branch, but in practice that never happens
(with RC1 we'll be cutting the 2.0.x branch, or at least
  we should, and the 1.7.x branch is still active)

Cheers
Andrea

--
Andrea Aime
OpenGeo - http://opengeo.org
Expert service straight from the developers.

Gabriel Roldan ha scritto:

Justin Deoliveira wrote:

I am actually sort of against mass formatting changes, as it usually ends up being more trouble than its worth. It also makes it really hard to apply patches among multiple branches.

concern shared. But for all means I mean it to try to keep it clean for new classes and patches, etc.
As an example, the new UI is not affected by backwards patching conflicts as it's a whole new thing, so that's perhaps _the_ one I would like to mass format, and as said keep an eye on any new code. Hope that makes more sense?

That would be good, it's actually a sweet spot.
Just make sure the commit only changes the formatting and maybe
give a heads up so that people do not have big and potentially
conflicting changes in the works

Cheers
Andrea

--
Andrea Aime
OpenGeo - http://opengeo.org
Expert service straight from the developers.

Andrea Aime wrote:

Gabriel Roldan ha scritto:

Hi guys,

It is a long time since I'm noticing an increasing loose of care on applying the code formatting we're supposed to. Not to mention tabs instead of spaces for indentation, lack of (c) headers, and even small but bothering breaks of the code conventions, like lack of braces in if statements. And also unused imports..

Agreed, that's annoying (quite a bit of the tabs are my fault, when
I switched to Linux I forgot to setup again the GeoTools code convention).

As for lack of braces, can you confirm that's part of the Sun Java
coding convention? I really hate to add extra braces if not necessary,
to me:

if(xxx)
   // one liner

reads much better than

if(xxx) {
   // one liner
}

I have to disagree here. It is readable only when the whitespace is formatted properly, and in many cases it is not. I prefer always to use braces to be on the safe side, but that is just a personal preference.

Our Eclipse formatter does not turn the first form into the second,
so I guess it is actually not part of the convention (either that
or the template is incomplete)

One thing that is annoying me instead is adding spaces in function calls, something like, f( a, b ) instead of f(a,b).
I don't know if the coding convention covers it, for sure the
Ecilpse formatter turns the first form into the latter.

Question is, is this deliberate? I bet not and would like to encourage all developers to systematically apply the formatting and follow conventions as described in <http://geoserver.org/display/GEOSDOC/1+Code+Conventions&gt;\.

As we all use eclipse and the formatter is there please just try to get used to press CTRL+ALT+F for formatting and CTRL+ALT+O for imports clean up... please?

Hmmm... I always clean imports, but never user CTRL-ALT-F because it
mixes together real changes with formatting ones.
If a file is really screwed up, I'd suggest to format it in both
branches (formatting just one is murder, makes porting patches
a nightmare) and make the commit a pure formatting one (no other changes).

Ideally we could mass reformat the code in a moment where there
is just one active branch, but in practice that never happens
(with RC1 we'll be cutting the 2.0.x branch, or at least
  we should, and the 1.7.x branch is still active)

Cheers
Andrea

--
Justin Deoliveira
OpenGeo - http://opengeo.org
Enterprise support for open source geospatial.

Justin Deoliveira ha scritto:

Andrea Aime wrote:

Gabriel Roldan ha scritto:

Hi guys,

It is a long time since I'm noticing an increasing loose of care on applying the code formatting we're supposed to. Not to mention tabs instead of spaces for indentation, lack of (c) headers, and even small but bothering breaks of the code conventions, like lack of braces in if statements. And also unused imports..

Agreed, that's annoying (quite a bit of the tabs are my fault, when
I switched to Linux I forgot to setup again the GeoTools code convention).

As for lack of braces, can you confirm that's part of the Sun Java
coding convention? I really hate to add extra braces if not necessary,
to me:

if(xxx)
   // one liner

reads much better than

if(xxx) {
   // one liner
}

I have to disagree here. It is readable only when the whitespace is formatted properly, and in many cases it is not. I prefer always to use braces to be on the safe side, but that is just a personal preference.

I can go for that, but then let's make the Eclipse formatter enforce
this.

No comment on the function call spaces? Can we trade horses here? :wink:
(nobody else actively committing with an opinion on this?)

Cheers
Andrea

--
Andrea Aime
OpenGeo - http://opengeo.org
Expert service straight from the developers.

Andrea Aime wrote:

Justin Deoliveira ha scritto:

Andrea Aime wrote:

Gabriel Roldan ha scritto:

Hi guys,

It is a long time since I'm noticing an increasing loose of care on applying the code formatting we're supposed to. Not to mention tabs instead of spaces for indentation, lack of (c) headers, and even small but bothering breaks of the code conventions, like lack of braces in if statements. And also unused imports..

Agreed, that's annoying (quite a bit of the tabs are my fault, when
I switched to Linux I forgot to setup again the GeoTools code convention).

As for lack of braces, can you confirm that's part of the Sun Java
coding convention? I really hate to add extra braces if not necessary,
to me:

if(xxx)
   // one liner

reads much better than

if(xxx) {
   // one liner
}

I have to disagree here. It is readable only when the whitespace is formatted properly, and in many cases it is not. I prefer always to use braces to be on the safe side, but that is just a personal preference.

I can go for that, but then let's make the Eclipse formatter enforce
this.

No comment on the function call spaces? Can we trade horses here? :wink:
(nobody else actively committing with an opinion on this?)

Oops, sorry missed that in the email. Yes I know I do this and am willing to give it up definitely, its just habit at this point. I need to find a way to get my keyboard so zap me when i open a ( and follow it with a space :slight_smile:

But in the interest of code formatting I will make myself do this. But please call me out when i forget.

Cheers
Andrea

--
Justin Deoliveira
OpenGeo - http://opengeo.org
Enterprise support for open source geospatial.

Andrea Aime ha scritto:

I have to disagree here. It is readable only when the whitespace is formatted properly, and in many cases it is not. I prefer always to use braces to be on the safe side, but that is just a personal preference.

I can go for that, but then let's make the Eclipse formatter enforce
this.

Btw, the Java coding convention actually says to always use braces here:
http://java.sun.com/docs/codeconv/html/CodeConventions.doc6.html#449
(thought a quick inspection in ArrayList sources shows the practice
  is the opposite, one liners almost never have braces around them)

No comment on the function call spaces? Can we trade horses here? :wink:
(nobody else actively committing with an opinion on this?)

I could not find an explicit statement, but looking at the examples here (or in any other page of the convention):
http://java.sun.com/docs/codeconv/html/CodeConventions.doc7.html#682
it would seem adding spaces after ( and before ) is not part of
the convention

Cheers
Andrea

--
Andrea Aime
OpenGeo - http://opengeo.org
Expert service straight from the developers.

Andrea Aime wrote:

Gabriel Roldan ha scritto:

Hi guys,

It is a long time since I'm noticing an increasing loose of care on applying the code formatting we're supposed to. Not to mention tabs instead of spaces for indentation, lack of (c) headers, and even small but bothering breaks of the code conventions, like lack of braces in if statements. And also unused imports..

Agreed, that's annoying (quite a bit of the tabs are my fault, when
I switched to Linux I forgot to setup again the GeoTools code convention).

As for lack of braces, can you confirm that's part of the Sun Java
coding convention?

yeah, it is: <http://java.sun.com/docs/codeconv/html/CodeConventions.doc6.html#449&gt;

I really hate to add extra braces if not necessary,

to me:

if(xxx)
  // one liner

reads much better than

if(xxx) {
  // one liner
}

Our Eclipse formatter does not turn the first form into the second,
so I guess it is actually not part of the convention (either that
or the template is incomplete)

looks like the template is incomplete :frowning:

One thing that is annoying me instead is adding spaces in function calls, something like, f( a, b ) instead of f(a,b).
I don't know if the coding convention covers it, for sure the
Ecilpse formatter turns the first form into the latter.

Some of the conventions were against my personal preferences too, but I've choose to stick to them back when the convention was introduced in geotools, as we wanted to have a common ground. Well, sort of, cause I was always as bad as you know at cleaning up javadocs and hence the huge amount of "DOCUMENT ME!" entries still there that Jaloppy loved to add...

Question is, is this deliberate? I bet not and would like to encourage all developers to systematically apply the formatting and follow conventions as described in <http://geoserver.org/display/GEOSDOC/1+Code+Conventions&gt;\.

As we all use eclipse and the formatter is there please just try to get used to press CTRL+ALT+F for formatting and CTRL+ALT+O for imports clean up... please?

Hmmm... I always clean imports, but never user CTRL-ALT-F because it
mixes together real changes with formatting ones.

That's right, hence when editing an existing file that doesn't already have the formatting applied, what I do is to select the new code and press CTRL+ALT+F so it formats only the selection instead of the whole file. That's a lot quicker than trying to stick to the conventions while typing.

If a file is really screwed up, I'd suggest to format it in both
branches (formatting just one is murder, makes porting patches
a nightmare) and make the commit a pure formatting one (no other changes).

I would like that too, wonder if jdeolive's concern about loosing blame ability is stronger than this one though...

Ideally we could mass reformat the code in a moment where there
is just one active branch, but in practice that never happens
(with RC1 we'll be cutting the 2.0.x branch, or at least
we should, and the 1.7.x branch is still active)

Yeah, I'd say we could live with a mid ground solution:
- apply full class formating only to classes not present in 1.7.x
- apply organize imports everywhere, that doesn't hurt blame ability
- commit to apply the formatting to any new code, when patching an existing class, format the patched section.

Cheers,
Gabriel

Cheers
Andrea

Gabriel Roldan ha scritto:

Ideally we could mass reformat the code in a moment where there
is just one active branch, but in practice that never happens
(with RC1 we'll be cutting the 2.0.x branch, or at least
we should, and the 1.7.x branch is still active)

Yeah, I'd say we could live with a mid ground solution:
- apply full class formating only to classes not present in 1.7.x
- apply organize imports everywhere, that doesn't hurt blame ability
- commit to apply the formatting to any new code, when patching an existing class, format the patched section.

I would be ok for doing a mass import on the classes that are not
in 1.7.x today, and then stay on the lookout for any formatting
breakage.
It makes blame harder to use, but not impossible, as one can
ask blame to comment on a specific version of the file:
e.g, from src/web/core on trunk try:

  svn blame -r 12819 ./src/main/java/org/geoserver/web/wicket/CRSPanel.java > CRSPanenelBlameR12819.java

svn blame ./src/main/java/org/geoserver/web/wicket/CRSPanel.java > CRSPanenelBlameHead.java

and compare the results (look for example the wktLink definition
which I chaged today).

It makes using blame cumbersome, as you first have to find the
revision at which the big reformat happened, but not impossible

Cheers
Andrea

--
Andrea Aime
OpenGeo - http://opengeo.org
Expert service straight from the developers.

Andrea Aime ha scritto:

Gabriel Roldan ha scritto:

Ideally we could mass reformat the code in a moment where there
is just one active branch, but in practice that never happens
(with RC1 we'll be cutting the 2.0.x branch, or at least
we should, and the 1.7.x branch is still active)

Yeah, I'd say we could live with a mid ground solution:
- apply full class formating only to classes not present in 1.7.x
- apply organize imports everywhere, that doesn't hurt blame ability
- commit to apply the formatting to any new code, when patching an existing class, format the patched section.

I would be ok for doing a mass import

a mass format, sorry

Cheers
Andrea

--
Andrea Aime
OpenGeo - http://opengeo.org
Expert service straight from the developers.

Andrea Aime wrote:

Gabriel Roldan ha scritto:

Ideally we could mass reformat the code in a moment where there
is just one active branch, but in practice that never happens
(with RC1 we'll be cutting the 2.0.x branch, or at least
we should, and the 1.7.x branch is still active)

Yeah, I'd say we could live with a mid ground solution:
- apply full class formating only to classes not present in 1.7.x
- apply organize imports everywhere, that doesn't hurt blame ability
- commit to apply the formatting to any new code, when patching an existing class, format the patched section.

I would be ok for doing a mass import on the classes that are not
in 1.7.x today, and then stay on the lookout for any formatting
breakage.
It makes blame harder to use, but not impossible, as one can
ask blame to comment on a specific version of the file:
e.g, from src/web/core on trunk try:

svn blame -r 12819 ./src/main/java/org/geoserver/web/wicket/CRSPanel.java > CRSPanenelBlameR12819.java

svn blame ./src/main/java/org/geoserver/web/wicket/CRSPanel.java > CRSPanenelBlameHead.java

and compare the results (look for example the wktLink definition
which I chaged today).

It makes using blame cumbersome, as you first have to find the
revision at which the big reformat happened, but not impossible

we could tag before and after applying, add a jira for it set the revision number there and a link to the tag, etc. If that's going to be of any help.

Cheers,
Gabriel

Cheers
Andrea

Justin Deoliveira wrote:

Andrea Aime wrote:

if(xxx)
   // one liner
reads much better than
if(xxx) {
   // one liner
}

I have to disagree here. It is readable only when the whitespace is formatted properly, and in many cases it is not. I prefer always to use braces to be on the safe side, but that is just a personal preference.

I agree with Justin, and use braces for all conditionals. When the Java compiler refuses to accept misleading indented code, perhaps I might change my view. :wink:

--
Ben Caradoc-Davies <Ben.Caradoc-Davies@anonymised.com>
Software Engineer, CSIRO Exploration and Mining
Australian Resources Research Centre
26 Dick Perry Ave, Kensington WA 6151, Australia

Andrea Aime wrote:

Hmmm... I always clean imports, but never user CTRL-ALT-F because it
mixes together real changes with formatting ones.

Ctrl-Shift-F, perhaps?

Reformatting of any kind is a judgement call. I avoid gratuitous reformatting unless I have refactored most of the code and claim exclusive blame (i.e. not often).

For the benefit of new players (not Andrea!) here are some other options for improving formatting of existing code in Eclipse. In order of decreasing intrusiveness (i.e. later is better):

(A) Select all (Ctrl-A) and fix indentation (Ctrl-I). I suspect this will break "svn blame" for many lines, but will fix all leading tabs without otherwise imposing your formatting on other code.

(B) Select the subset you are working on and reformat (Ctrl-Shift-F). Use Compare With > Base Revision to ensure your reformat did not change lines outside your intended local changes.

(C) Select subset and and fix indentation (Ctrl-I). Again, check against the base revision.

Again, consistency with convention versus consistency with existing code is a judgement call. Avoid having to use your judgement :wink:
by producing all new code formatted to spec:
(1) use the GeoTools Eclipse formatter config and
(2) use Ctrl-Shift-O, Ctrl-Shift-F, Ctrl-S before any commit.

Another trick I use is end-of-line comments (//) to defeat Eclipse line wrapping when it is inappropriate or does a terrible job.

Kind regards,

--
Ben Caradoc-Davies <Ben.Caradoc-Davies@anonymised.com>
Software Engineer, CSIRO Exploration and Mining
Australian Resources Research Centre
26 Dick Perry Ave, Kensington WA 6151, Australia