You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@aries.apache.org by Guillaume Nodet <gn...@gmail.com> on 2010/02/16 11:07:33 UTC

[DISCUSS] Code formatting

I'd like aries to try using a single coding standards.
Specifically, i'd like us to agree on indentation rules (the code uses
2 or 4 spaces in different places).
I'd like to propose the geronimo coding standards which is in use in a
lot of projects at apache.
See http://geronimo.apache.org/coding-standards.html

Btw, I really don't think we should enforce those at all cost using
maven plugins or such, but agreeing on
those would allow to reformat the code once and not go back and forth
between different standards.

-- 
Cheers,
Guillaume Nodet
------------------------
Blog: http://gnodet.blogspot.com/
------------------------
Open Source SOA
http://fusesource.com

Re: [DISCUSS] Code formatting

Posted by Guillaume Nodet <gn...@gmail.com>.
On Tue, Feb 16, 2010 at 17:01, Timothy Ward <ti...@apache.org> wrote:
>
> I also prefer 2 spaces to 4, it saves a lot of space in nested blocks.
>
> I would say, however, that I don't really believe in "house style" when it comes to code formatting. It is entirely possible to format code as an unreadable mess, but my experience has always been that any "real" code is presented in a readable format. It may not follow my exact personal preference, but I don't think that means it should be changed. I agree that it's polite to follow the tab size already in the file, which I believe is the case throughout the codebase, even if there are some files that use 2 spaces and others that use 4.
>
> Personally, I don't think there's a readability problem in the Aries source and therefore I don't think that we need to establish code formatting rules. Equally, it's not that important an issue and definitely not worth starting an argument over!

Definitely, though and fwiw, I'm quite used to 4 spaces.  I think it's
more easy to spot the blocks and I may be wrong, but I think the issue
I've fixed (http://svn.apache.org/viewvc/incubator/aries/trunk/application/application-management/src/main/java/org/apache/aries/application/management/impl/AriesApplicationManagerImpl.java?r1=910441&r2=910440&pathrev=910441)
could have been avoided by using a bigger indentation (the if block
was inside the loop block inside of just after).

Anyway, the code is quite clean for now, so that's not a big deal as
along as we keep it that way.

>
> Regards,
>
> Tim
>
>> Date: Tue, 16 Feb 2010 11:46:26 +0000
>> Subject: Re: [DISCUSS] Code formatting
>> From: not@apache.org
>> To: aries-dev@incubator.apache.org
>>
>> I always worry about establishing code formatting guides because in my
>> experience it often devolves into unproductive arguments.
>>
>> Scanning through the geronimo guides the only things I do not
>> particularly like are:
>>
>> 1. I prefer 2 spaces for indent to 4. It gives you more line length
>> for actual code to fix.
>> 2. I prefer methods and classes to put the curly brace on a new line.
>> It helps me to identify where the method starts.
>>
>> In my view the primary rule for any code formatting rules is that they
>> be consistent within a file. So if a file uses 4 spaces for indent,
>> you use 4 (or you change it to 2 consistently in the file). I also
>> think you should only change the code formatting if you are a
>> significant contributor to the file.
>>
>> I defiantly agree that tabs should be banned in any source file :)
>>
>> Alasdair
>>
>> On 16 February 2010 10:25, Jeremy Hughes <hu...@apache.org> wrote:
>> > On 16 February 2010 10:07, Guillaume Nodet <gn...@gmail.com> wrote:
>> >> I'd like aries to try using a single coding standards.
>> >> Specifically, i'd like us to agree on indentation rules (the code uses
>> >> 2 or 4 spaces in different places).
>> >> I'd like to propose the geronimo coding standards which is in use in a
>> >> lot of projects at apache.
>> >> See http://geronimo.apache.org/coding-standards.html
>> >
>> > I had a quick look. I agree to no tabs and prefer 2 spaces to 4. I
>> > also think this needs to apply to xml.
>> >
>> > Whatever the convention is, we should be able to codify it in an
>> > Eclipse code formatter profile (and equivalents for other IDE). If the
>> > formatting convention requires manual steps to apply - i.e. anything
>> > more than: select-all then ctrl-shift-f to format, then I don't think
>> > it will be applied consistently.
>> >
>> >>
>> >> Btw, I really don't think we should enforce those at all cost using
>> >> maven plugins or such,
>> >
>> > I didn't know there was one! This actually sounds like a perfectly
>> > reasonable thing to do - like removing compile warnings, and fixing or
>> > filtering issues findbugs finds. So on the face of it I'm actually +1
>> > for this.
>> >
>> >> but agreeing on
>> >> those would allow to reformat the code once and not go back and forth
>> >> between different standards.
>> > +1 !!
>> >
>> > Cheers,
>> > Jeremy
>> >
>>
>>
>>
>> --
>> Alasdair Nottingham
>> not@apache.org
>
> _________________________________________________________________
> Tell us your greatest, weirdest and funniest Hotmail stories
> http://clk.atdmt.com/UKM/go/195013117/direct/01/



-- 
Cheers,
Guillaume Nodet
------------------------
Blog: http://gnodet.blogspot.com/
------------------------
Open Source SOA
http://fusesource.com

Re: [DISCUSS] Code formatting

Posted by "Alan D. Cabrera" <li...@toolazydogs.com>.
I prefer 4 to 2 spaces because it makes the code easier to read.  I  
don't worry about nested blocks because if it becomes an issue then  
that's usually a red flag that I'm writing or, worse, reading  
spaghetti code.

I prefer the brackets on the next line because it makes the code  
easier to read.

imho, the coding conventions from Geronimo were influenced by a long  
standing formatting tradition started when BSD Unix was written.  In  
those days screen space was a premium and so issues such as  
readability took a back seat to more pragmatic issues such as fitting  
the function that you were writing on the screen.  As someone who used  
to write large bodies of code on punched cards I can happily say that  
those days are, thankfully, over.

Having multiple coding conventions for this project, imnsho, is  
ridiculous.


Regards,
Alan

On Feb 16, 2010, at 8:01 AM, Timothy Ward wrote:

>
> I also prefer 2 spaces to 4, it saves a lot of space in nested blocks.
>
> I would say, however, that I don't really believe in "house style"  
> when it comes to code formatting. It is entirely possible to format  
> code as an unreadable mess, but my experience has always been that  
> any "real" code is presented in a readable format. It may not follow  
> my exact personal preference, but I don't think that means it should  
> be changed. I agree that it's polite to follow the tab size already  
> in the file, which I believe is the case throughout the codebase,  
> even if there are some files that use 2 spaces and others that use 4.
>
> Personally, I don't think there's a readability problem in the Aries  
> source and therefore I don't think that we need to establish code  
> formatting rules. Equally, it's not that important an issue and  
> definitely not worth starting an argument over!
>
> Regards,
>
> Tim
>
>> Date: Tue, 16 Feb 2010 11:46:26 +0000
>> Subject: Re: [DISCUSS] Code formatting
>> From: not@apache.org
>> To: aries-dev@incubator.apache.org
>>
>> I always worry about establishing code formatting guides because in  
>> my
>> experience it often devolves into unproductive arguments.
>>
>> Scanning through the geronimo guides the only things I do not
>> particularly like are:
>>
>> 1. I prefer 2 spaces for indent to 4. It gives you more line length
>> for actual code to fix.
>> 2. I prefer methods and classes to put the curly brace on a new line.
>> It helps me to identify where the method starts.
>>
>> In my view the primary rule for any code formatting rules is that  
>> they
>> be consistent within a file. So if a file uses 4 spaces for indent,
>> you use 4 (or you change it to 2 consistently in the file). I also
>> think you should only change the code formatting if you are a
>> significant contributor to the file.
>>
>> I defiantly agree that tabs should be banned in any source file :)
>>
>> Alasdair
>>
>> On 16 February 2010 10:25, Jeremy Hughes <hu...@apache.org> wrote:
>>> On 16 February 2010 10:07, Guillaume Nodet <gn...@gmail.com> wrote:
>>>> I'd like aries to try using a single coding standards.
>>>> Specifically, i'd like us to agree on indentation rules (the code  
>>>> uses
>>>> 2 or 4 spaces in different places).
>>>> I'd like to propose the geronimo coding standards which is in use  
>>>> in a
>>>> lot of projects at apache.
>>>> See http://geronimo.apache.org/coding-standards.html
>>>
>>> I had a quick look. I agree to no tabs and prefer 2 spaces to 4. I
>>> also think this needs to apply to xml.
>>>
>>> Whatever the convention is, we should be able to codify it in an
>>> Eclipse code formatter profile (and equivalents for other IDE). If  
>>> the
>>> formatting convention requires manual steps to apply - i.e. anything
>>> more than: select-all then ctrl-shift-f to format, then I don't  
>>> think
>>> it will be applied consistently.
>>>
>>>>
>>>> Btw, I really don't think we should enforce those at all cost using
>>>> maven plugins or such,
>>>
>>> I didn't know there was one! This actually sounds like a perfectly
>>> reasonable thing to do - like removing compile warnings, and  
>>> fixing or
>>> filtering issues findbugs finds. So on the face of it I'm actually  
>>> +1
>>> for this.
>>>
>>>> but agreeing on
>>>> those would allow to reformat the code once and not go back and  
>>>> forth
>>>> between different standards.
>>> +1 !!
>>>
>>> Cheers,
>>> Jeremy
>>>
>>
>>
>>
>> -- 
>> Alasdair Nottingham
>> not@apache.org
> 		 	   		
> _________________________________________________________________
> Tell us your greatest, weirdest and funniest Hotmail stories
> http://clk.atdmt.com/UKM/go/195013117/direct/01/


RE: [DISCUSS] Code formatting

Posted by Timothy Ward <ti...@apache.org>.
I also prefer 2 spaces to 4, it saves a lot of space in nested blocks.

I would say, however, that I don't really believe in "house style" when it comes to code formatting. It is entirely possible to format code as an unreadable mess, but my experience has always been that any "real" code is presented in a readable format. It may not follow my exact personal preference, but I don't think that means it should be changed. I agree that it's polite to follow the tab size already in the file, which I believe is the case throughout the codebase, even if there are some files that use 2 spaces and others that use 4.

Personally, I don't think there's a readability problem in the Aries source and therefore I don't think that we need to establish code formatting rules. Equally, it's not that important an issue and definitely not worth starting an argument over! 

Regards,

Tim

> Date: Tue, 16 Feb 2010 11:46:26 +0000
> Subject: Re: [DISCUSS] Code formatting
> From: not@apache.org
> To: aries-dev@incubator.apache.org
> 
> I always worry about establishing code formatting guides because in my
> experience it often devolves into unproductive arguments.
> 
> Scanning through the geronimo guides the only things I do not
> particularly like are:
> 
> 1. I prefer 2 spaces for indent to 4. It gives you more line length
> for actual code to fix.
> 2. I prefer methods and classes to put the curly brace on a new line.
> It helps me to identify where the method starts.
> 
> In my view the primary rule for any code formatting rules is that they
> be consistent within a file. So if a file uses 4 spaces for indent,
> you use 4 (or you change it to 2 consistently in the file). I also
> think you should only change the code formatting if you are a
> significant contributor to the file.
> 
> I defiantly agree that tabs should be banned in any source file :)
> 
> Alasdair
> 
> On 16 February 2010 10:25, Jeremy Hughes <hu...@apache.org> wrote:
> > On 16 February 2010 10:07, Guillaume Nodet <gn...@gmail.com> wrote:
> >> I'd like aries to try using a single coding standards.
> >> Specifically, i'd like us to agree on indentation rules (the code uses
> >> 2 or 4 spaces in different places).
> >> I'd like to propose the geronimo coding standards which is in use in a
> >> lot of projects at apache.
> >> See http://geronimo.apache.org/coding-standards.html
> >
> > I had a quick look. I agree to no tabs and prefer 2 spaces to 4. I
> > also think this needs to apply to xml.
> >
> > Whatever the convention is, we should be able to codify it in an
> > Eclipse code formatter profile (and equivalents for other IDE). If the
> > formatting convention requires manual steps to apply - i.e. anything
> > more than: select-all then ctrl-shift-f to format, then I don't think
> > it will be applied consistently.
> >
> >>
> >> Btw, I really don't think we should enforce those at all cost using
> >> maven plugins or such,
> >
> > I didn't know there was one! This actually sounds like a perfectly
> > reasonable thing to do - like removing compile warnings, and fixing or
> > filtering issues findbugs finds. So on the face of it I'm actually +1
> > for this.
> >
> >> but agreeing on
> >> those would allow to reformat the code once and not go back and forth
> >> between different standards.
> > +1 !!
> >
> > Cheers,
> > Jeremy
> >
> 
> 
> 
> -- 
> Alasdair Nottingham
> not@apache.org
 		 	   		  
_________________________________________________________________
Tell us your greatest, weirdest and funniest Hotmail stories
http://clk.atdmt.com/UKM/go/195013117/direct/01/

Re: [DISCUSS] Code formatting

Posted by Alasdair Nottingham <no...@apache.org>.
I always worry about establishing code formatting guides because in my
experience it often devolves into unproductive arguments.

Scanning through the geronimo guides the only things I do not
particularly like are:

1. I prefer 2 spaces for indent to 4. It gives you more line length
for actual code to fix.
2. I prefer methods and classes to put the curly brace on a new line.
It helps me to identify where the method starts.

In my view the primary rule for any code formatting rules is that they
be consistent within a file. So if a file uses 4 spaces for indent,
you use 4 (or you change it to 2 consistently in the file). I also
think you should only change the code formatting if you are a
significant contributor to the file.

I defiantly agree that tabs should be banned in any source file :)

Alasdair

On 16 February 2010 10:25, Jeremy Hughes <hu...@apache.org> wrote:
> On 16 February 2010 10:07, Guillaume Nodet <gn...@gmail.com> wrote:
>> I'd like aries to try using a single coding standards.
>> Specifically, i'd like us to agree on indentation rules (the code uses
>> 2 or 4 spaces in different places).
>> I'd like to propose the geronimo coding standards which is in use in a
>> lot of projects at apache.
>> See http://geronimo.apache.org/coding-standards.html
>
> I had a quick look. I agree to no tabs and prefer 2 spaces to 4. I
> also think this needs to apply to xml.
>
> Whatever the convention is, we should be able to codify it in an
> Eclipse code formatter profile (and equivalents for other IDE). If the
> formatting convention requires manual steps to apply - i.e. anything
> more than: select-all then ctrl-shift-f to format, then I don't think
> it will be applied consistently.
>
>>
>> Btw, I really don't think we should enforce those at all cost using
>> maven plugins or such,
>
> I didn't know there was one! This actually sounds like a perfectly
> reasonable thing to do - like removing compile warnings, and fixing or
> filtering issues findbugs finds. So on the face of it I'm actually +1
> for this.
>
>> but agreeing on
>> those would allow to reformat the code once and not go back and forth
>> between different standards.
> +1 !!
>
> Cheers,
> Jeremy
>



-- 
Alasdair Nottingham
not@apache.org

Re: [DISCUSS] Code formatting

Posted by David Bosschaert <da...@gmail.com>.
Hi all,

I definitely agree to no tabs. On 2 vs 4 spaces I'm pretty neutral
although I'm tempted to suggest the middle ground: 3 spaces (lol)

On using tools that enforce the coding standards (like
checkstyle/PMD), while they sound appealing they can be a PITA. My
experience is that even though certain rules might sound reasonable,
there might be reasons not to follow them occasionally. Just to give
two examples from my past
1. The formatter system that was used in a build system for a project
I was active in restricted the number of methods in a class, to avoid
creating classes that are too big. This might be ok, until you are
writing a class that needs to implement an external interface with >50
methods (they do exist!)
2. Sometimes rules for product code aren't really valid for test code.
In the past the formatting rules I had to work with restricted the
number of lines in a method. This was ok for runtime code, but not for
test code where some of the tests were a little like a script running
a lot of actions in sequence...

It would be nice if we can somewhere store code formatter definitions
for all the popular IDEs so that people can simply import them and be
safe that way.

Cheers,

David

On 16 February 2010 10:25, Jeremy Hughes <hu...@apache.org> wrote:
> On 16 February 2010 10:07, Guillaume Nodet <gn...@gmail.com> wrote:
>> I'd like aries to try using a single coding standards.
>> Specifically, i'd like us to agree on indentation rules (the code uses
>> 2 or 4 spaces in different places).
>> I'd like to propose the geronimo coding standards which is in use in a
>> lot of projects at apache.
>> See http://geronimo.apache.org/coding-standards.html
>
> I had a quick look. I agree to no tabs and prefer 2 spaces to 4. I
> also think this needs to apply to xml.
>
> Whatever the convention is, we should be able to codify it in an
> Eclipse code formatter profile (and equivalents for other IDE). If the
> formatting convention requires manual steps to apply - i.e. anything
> more than: select-all then ctrl-shift-f to format, then I don't think
> it will be applied consistently.
>
>>
>> Btw, I really don't think we should enforce those at all cost using
>> maven plugins or such,
>
> I didn't know there was one! This actually sounds like a perfectly
> reasonable thing to do - like removing compile warnings, and fixing or
> filtering issues findbugs finds. So on the face of it I'm actually +1
> for this.
>
>> but agreeing on
>> those would allow to reformat the code once and not go back and forth
>> between different standards.
> +1 !!
>
> Cheers,
> Jeremy
>

Re: [DISCUSS] Code formatting

Posted by Jeremy Hughes <hu...@apache.org>.
On 16 February 2010 10:07, Guillaume Nodet <gn...@gmail.com> wrote:
> I'd like aries to try using a single coding standards.
> Specifically, i'd like us to agree on indentation rules (the code uses
> 2 or 4 spaces in different places).
> I'd like to propose the geronimo coding standards which is in use in a
> lot of projects at apache.
> See http://geronimo.apache.org/coding-standards.html

I had a quick look. I agree to no tabs and prefer 2 spaces to 4. I
also think this needs to apply to xml.

Whatever the convention is, we should be able to codify it in an
Eclipse code formatter profile (and equivalents for other IDE). If the
formatting convention requires manual steps to apply - i.e. anything
more than: select-all then ctrl-shift-f to format, then I don't think
it will be applied consistently.

>
> Btw, I really don't think we should enforce those at all cost using
> maven plugins or such,

I didn't know there was one! This actually sounds like a perfectly
reasonable thing to do - like removing compile warnings, and fixing or
filtering issues findbugs finds. So on the face of it I'm actually +1
for this.

> but agreeing on
> those would allow to reformat the code once and not go back and forth
> between different standards.
+1 !!

Cheers,
Jeremy

Re: [DISCUSS] Code formatting

Posted by David Jencks <da...@yahoo.com>.
On Feb 16, 2010, at 2:07 AM, Guillaume Nodet wrote:

> I'd like aries to try using a single coding standards.
> Specifically, i'd like us to agree on indentation rules (the code uses
> 2 or 4 spaces in different places).
> I'd like to propose the geronimo coding standards which is in use in a
> lot of projects at apache.
> See http://geronimo.apache.org/coding-standards.html

I think that all the apache projects I know about use 4 spaces, no  
tabs for java.  There's more disagreement about where the { goes.  I  
think that in this case having the code look more like other apache  
projects is a significant ease-of-transition factor that we might  
subordinate our preferences based on personal experience to.

So, based partly on my strong preference for 4 spaces and being used  
to it, I'd vote for 4 spaces.
>
> Btw, I really don't think we should enforce those at all cost using
> maven plugins or such, but agreeing on
> those would allow to reformat the code once and not go back and forth
> between different standards.
>
I agree.  I find it very hard to work on projects that enforce coding  
standards, it typically takes longer to decipher what the plugin  
thinks is wrong than to make the code changes I was interested in.

thanks
david jencks

> -- 
> Cheers,
> Guillaume Nodet
> ------------------------
> Blog: http://gnodet.blogspot.com/
> ------------------------
> Open Source SOA
> http://fusesource.com