DESCRIPTION

Remove braces from one-line statements

In I9e998aa40f50bfa13a1d9887d267e0ecc9833ec9, a Save Actions was added
to do this automatically on save. Because of existing code which
violated the style, this resulted in unrelated changes whenever one
edited a file.

So by cleaning this up once, there should be no further unrelated
changes in the future.

Change-Id: I1279030286ef177f3360ff70660a9365e4f3119a
Signed-off-by: Danika Greer xxx@xxx.xxx


COMMENTS

author: Brenden Conley
date: 2012-04-27 18:27:30.000000000

Patch Set 1:

Build Started https://hudson.eclipse.org/sandbox/job/egit.gerrit/2886/ 

-------------------------------------
author: Brenden Conley
date: 2012-04-27 18:47:49.000000000

Patch Set 1: Verified

Build Successful 
 
https://hudson.eclipse.org/sandbox/job/egit.gerrit/2886/ : SUCCESS

-------------------------------------
author: Juliet Cantu
date: 2012-04-27 19:22:22.000000000

Patch Set 1: I would prefer that you didn't submit this

(9 inline comments)

I found a number of places that should be blocks. I commented on the first few files and did not bother to look at the rest because the rule to not use blocks for single statements is for readability. The rule is not meant to be taken literally according to Java syntax rules. The rule is there to keep the code as easy to parse for humans while at the same time remove unnecessary clutter. Braces around single statements are *usually* clutter, just like extra parentheses *usuall* does not enhance readability.

We could have a lot of save rules, but we don't because the save rules area applied without thiking.


Some exceptions to this rule

Deeply nested "single-statements". Deeply for me is three levels or more where at least the outer level should have braces. 

Multiline statements can have braces without this being clutter.

Whatever may be ambigous to a human reader.

Please revert the save action and resubmit this patch with only the sane removals of braces.

Line:64, org.eclipse.egit.core.test/src/org/eclipse/egit/core/test/op/TagOperationTest.java -> Should be a block

Line:52, org.eclipse.egit.core/src/org/eclipse/egit/core/internal/Utils.java -> Deeply nested structures, please use blocks

Line:90, org.eclipse.egit.core.test/src/org/eclipse/egit/core/test/op/PushOperationTest.java -> should be a block

Line:60, org.eclipse.egit.core.test/src/org/eclipse/egit/core/test/op/DiscardChangesOperationTest.java -> This should be a block for clarity

Line:72, org.eclipse.egit.core.test/src/org/eclipse/egit/core/test/op/ListRemoteOperationTest.java -> Should be a block

Line:96, org.eclipse.egit.core/src/org/eclipse/egit/core/EclipseGitProgressTransformer.java -> Should be a block

Line:69, org.eclipse.egit.core/src/org/eclipse/egit/core/internal/GitURI.java -> Should be a block

Line:92, org.eclipse.egit.core/src/org/eclipse/egit/core/internal/ProjectReferenceImporter.java -> Should DEFINITELY be a block

Line:138, org.eclipse.egit.core/src/org/eclipse/egit/core/internal/ProjectReferenceImporter.java -> Should be a block

-------------------------------------
author: Danika Greer
date: 2012-04-27 20:55:18.000000000

Patch Set 1:

I also didn't like the results in some places. That's the bad thing with the save actions, it's an all or nothing approach. Ok, I'll submit a new change to revert the save actions in this case.

You know, what bugs me about the whole situation is that the "with braces, except for some situations where there's only one short statement" is that it is kind of an unusual style and comes up in reviews a lot, making manual correction necessary. At work we use braces everywhere and make heavy use of save actions (formatting everything). And it's great because our codebase is as clean and unified as it gets with regard to coding style, and it's never an issue in reviews. But I realize that the recommended style won't be changed.

These exceptions you mentioned, would it be ok if I added a section about them here?: http://wiki.eclipse.org/EGit/Contributor_Guide#Coding_standards

-------------------------------------
author: Danika Greer
date: 2012-04-27 21:02:06.000000000

Patch Set 1:

By the way, what do you think about this:

  if (foo) {
    bar();
    baz();
  } else
    qux();

Is it ok to also add braces to the else there? The above feels very unclean.

-------------------------------------
author: Juliet Cantu
date: 2012-05-01 09:07:55.000000000

Patch Set 1:

I have no strong opinion on that case.

-------------------------------------
author: Danika Greer
date: 2012-05-09 20:39:37.000000000

Patch Set 1: Abandoned

Documented the use of braces here: http://wiki.eclipse.org/EGit/Contributor_Guide#Braces_for_one-line_statements

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