You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@creadur.apache.org by Hugo Hirsch <as...@hugo-hirsch.de> on 2011/11/26 13:02:02 UTC

RAT-103: Automated code formatting for better readability / Opinions

Hi *,

I've proposed an automated code formatting via Jira
(https://issues.apache.org/jira/browse/RAT-103) -
that means with each mvn run the sources are formatted based on a
default formatter (attached to the issue as well).

Thus there are major changes when the plugin is enabled. Afterwards
reformatting only applies to patches.

The main goal of this is a cleaner readability of the code since some
parts are formatted in C-style, others in Java-style, others in free
style :-) I'd be happy to see a uniquely formatted code before the
project leaves the incubator.

Any objections/opinions?

Yours
Hugo


Re: RAT-103: Automated code formatting for better readability / Opinions

Posted by sebb <se...@gmail.com>.
On 27 November 2011 12:30, Hugo Hirsch <as...@hugo-hirsch.de> wrote:
> Hi again,
>
> Am 27.11.2011 12:24, schrieb sebb:
>>> > Of course code can be reformatted in various ways - but my proposal runs
>>> > automatically and needs no fine tuning on each plattform or special
>>> > IDE-settings.
>> However, that does not automatically ensure that the reformatting
>> preserves comments in a readable format.
>>
>> I suggest you attach some sample before and after files to the JIRA.
>
> The plugin relies on a formatter.xml file - I attached a sample to RAT-103.
>
> No javadoc is touched. The reformatting only applies to code, not
> comments etc.

This can be a problem where comments are indented to agree with code.

> No logic etc. is changed at all! It's just a formatter.
>
> I applied a before/after of
> apache-rat-core/src/main/java/org/apache/rat/document/impl/guesser/BinaryGuesser.java
> to RAT-103.

I've replied there.

> The settings in the ratFormatter.xml can be tweaked if there any wishes
> :-) It's just a proposal to open discussion.
>
> HTH
> Hugo
>

Re: RAT-103: Automated code formatting for better readability / Opinions

Posted by Hugo Hirsch <as...@hugo-hirsch.de>.
Hi again,

Am 27.11.2011 12:24, schrieb sebb:
>> > Of course code can be reformatted in various ways - but my proposal runs
>> > automatically and needs no fine tuning on each plattform or special
>> > IDE-settings.
> However, that does not automatically ensure that the reformatting
> preserves comments in a readable format.
> 
> I suggest you attach some sample before and after files to the JIRA.

The plugin relies on a formatter.xml file - I attached a sample to RAT-103.

No javadoc is touched. The reformatting only applies to code, not
comments etc. No logic etc. is changed at all! It's just a formatter.

I applied a before/after of
apache-rat-core/src/main/java/org/apache/rat/document/impl/guesser/BinaryGuesser.java
to RAT-103.

The settings in the ratFormatter.xml can be tweaked if there any wishes
:-) It's just a proposal to open discussion.

HTH
Hugo

Re: RAT-103: Automated code formatting for better readability / Opinions

Posted by sebb <se...@gmail.com>.
On 26 November 2011 12:17, Hugo Hirsch <as...@hugo-hirsch.de> wrote:
> Hi,
>
> thanks for your ideas.
>
> Am 26.11.2011 13:13, schrieb sebb:
>> Is there a single Java style? or C style for that matter?
>
> To my mind this is c-style:
>
> public void foo()
> {
> ...
>
> while this is java style:
> public void foo() {
> ....
>
> This applies to many more code snippets :-p

I marginally prefer the latter, as it requires fewer lines, so one can
see more of the code on a single screen.

However the former is a bit easier to navigate visually; and it's
easier to temporarily change conditions. e.g.

if (condition)
{
    code
}

can be easily changed to force the condition by commenting it (most
IDEs have a line comment toggle).
I used that only recently in some debugging I was doing.

But it's not a reason to change.

> Of course code can be reformatted in various ways - but my proposal runs
> automatically and needs no fine tuning on each plattform or special
> IDE-settings.

However, that does not automatically ensure that the reformatting
preserves comments in a readable format.

I suggest you attach some sample before and after files to the JIRA.

> Yours,
> Hugo
>

Re: RAT-103: Automated code formatting for better readability / Opinions

Posted by Hugo Hirsch <as...@hugo-hirsch.de>.
Hi,

thanks for your ideas.

Am 26.11.2011 13:13, schrieb sebb:
> Is there a single Java style? or C style for that matter?

To my mind this is c-style:

public void foo()
{
...

while this is java style:
public void foo() {
....

This applies to many more code snippets :-p

Of course code can be reformatted in various ways - but my proposal runs
automatically and needs no fine tuning on each plattform or special
IDE-settings.

Yours,
Hugo

Re: RAT-103: Automated code formatting for better readability / Opinions

Posted by sebb <se...@gmail.com>.
On 26 November 2011 12:02, Hugo Hirsch <as...@hugo-hirsch.de> wrote:
> Hi *,
>
> I've proposed an automated code formatting via Jira
> (https://issues.apache.org/jira/browse/RAT-103) -
> that means with each mvn run the sources are formatted based on a
> default formatter (attached to the issue as well).
>
> Thus there are major changes when the plugin is enabled. Afterwards
> reformatting only applies to patches.
>
> The main goal of this is a cleaner readability of the code since some
> parts are formatted in C-style, others in Java-style, others in free

Is there a single Java style? or C style for that matter?

;-)

> style :-) I'd be happy to see a uniquely formatted code before the
> project leaves the incubator.
>
> Any objections/opinions?

Unless the code is very badly formatted, I'm not sure it's worth the
extra effort.
I'm still finding mangled (badly wrapped) comments in code that was
reformatted years ago.

However, I would recommend at least:
- removing all tabs
- ensuring consistent indentation (Java 4 spaces; XML 4 or 2)

I think these can be done with little or no adverse affect.

Also, once those are done, re-inspect the code and see if is still too diverse.

> Yours
> Hugo
>
>

Re: RAT-103: Automated code formatting for better readability / Opinions

Posted by Hugo Hirsch <as...@hugo-hirsch.de>.
Hi,

Am 27.11.2011 08:10, schrieb Stefan Bodewig:
> As far as fixing the inconsistencies we currently have I'd be happy with
> removing tabs and having a consistent indentation (be careful with the
> XSLTs here) and don't really care much about brace placement or spaces
> between operators.

The plugin works in *.java only - so no problems with XML/XSLT stuff.

I'll attach a patch to the bug since people seem to be afraid of plugins
here :-)

Yours
Hugo

Re: RAT-103: Automated code formatting for better readability / Opinions

Posted by Stefan Bodewig <bo...@apache.org>.
On 2011-11-26, Hugo Hirsch wrote:

> (https://issues.apache.org/jira/browse/RAT-103) -
> that means with each mvn run the sources are formatted based on a
> default formatter (attached to the issue as well).

Like I said over there I don't really like the idea of a plugin
modifying the code after I have written it, so -0 on using the plugin.

As far as fixing the inconsistencies we currently have I'd be happy with
removing tabs and having a consistent indentation (be careful with the
XSLTs here) and don't really care much about brace placement or spaces
between operators.

Stefan