On Jul 19, 2013, at 2:35 PM, Glen Mazza wrote:

> Hi Team, the next Sonar complaint, and there's a significant 500 of them 
> within JSPWiki, is that we're not using braces for single-line if/while/for 
> loops.  I know for CXF braces are always required, and I suspect the majority 
> of Apache projects today also disallow them, so the requirement is not 
> unreasonable.  Fixing them is not the problem, what *is* the problem is our 
> older-fashioned bracing system, i.e., instead of switching from this
> 
> Style A:
> 
> if (a > b)
>   c = 10;
> else if (d > e)
>   f = 20;
> 
> to this (the bracing system JSPWiki presently uses):
> 
> Style B:
> 
> if (a > b)
> {
>   c = 10;
> }
> else if (d > e)
> {
>   f = 20;
> }
> 
> I'd like to be doing this instead:
> 
> Style C:
> 
> if (a > b) {
>   c = 10;
> } else if (d > e) {
>   f = 20;
> }
> 

> I've checked five major open source projects -- Style C is all they use:
> 
> CXF - 
> http://svn.apache.org/viewvc/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/https/CertConstraintsFeature.java?revision=828758&view=markup
> 
> Camel - 
> http://svn.apache.org/viewvc/camel/trunk/components/camel-atom/src/main/java/org/apache/camel/component/atom/AtomUtils.java?revision=1190212&view=markup
> 
> Tomcat - 
> http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/filters/FilterBase.java?revision=1189413&view=markup
> 
> Hadoop - 
> http://svn.apache.org/viewvc/hadoop/common/trunk/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-common/src/main/java/org/apache/hadoop/mapred/LocalDistributedCacheManager.java?revision=1466196&view=markup
> 
> Spring Framework: 
> https://github.com/SpringSource/spring-framework/blob/master/spring-jdbc/src/main/java/org/springframework/jdbc/object/SqlFunction.java
> 
> Style B might be OK for projects that still allow Style A, but it makes the 
> code too bloated once Style A is disallowed.  I don't think we'll be able to 
> attract many committers sticking with Style B anymore.  Basically, to avoid 
> the busywork of converting Style B to Style C, we'll allow either in our 
> source code but with the expectation that more and more code will be adopting 
> Style C as time moves on, how does that sound?  (Or, do we want to continue 
> with allowing Style A and Style B?--we're welcome to ignore Sonar on this.)

For what it's worth, the Java projects I work on regularly (and starting to use 
in Javascript as well) is Style C. I do believe it is the more modern style and 
in fact IIRC these other projects copied Style C from internal Sun Java 
development style guidelines 8 years ago.

I don't believe that Style A should be allowed on any project anywhere in the 
known universe. It's too easy to make mistakes in both complex if else if else 
(where do the elses belong?) and adding a new line to the if or else clause.

So +1 for Style C.

Craig

P.S. I'm not a coder on the project so please feel free to go your own way on 
this.

> 
> Regards,
> Glen
> 

Craig L Russell
Architect, Oracle
http://db.apache.org/jdo
408 276-5638 mailto:craig.russ...@oracle.com
P.S. A good JDO? O, Gasp!

Reply via email to