Monday, June 12, 2006

Code Conventions

Brandon Franklin recently asked the following question on AJUG (Australian Java Users Group) and SeaJUG (Seattle Java Users Group):

At your company, are the { } placed using the Sun Standard, like this:

public void method() {
}

or using the "C way", like this:

public void method()
{
}

A day later, he posted the results of his survey back to these mailing lists. There were 68 responses: 35 from AJUG and 33 from SeaJUG. Basically there were three types of responses: same line opening bracket, next line opening bracket, and "either" or "no standard". And here is how each type was in favour:

          SAME LINE     NEXT LINE/ALIGNED      EITHER
AJUG 60% 37% 3%
SeaJUG 58% 33% 9%
COMBINED 59% 35% 6%

The conclusion that Brandon came to was that the majority of Java development houses seem to use the Sun standard, with a solid third still using the "next line braces" approach.

I am not going to say which one you should choose. In my experience, the majority of companies I worked for used same line style. In fact, all of them, but one used it. So the ratio in my case would be 4:1 for same line style. When it comes to number of projects I worked on, it gets better (or worse, depending on how you look at it). The per projects ratio would be (and that's only because I can not remember all the small and small-ish projects I worked on) somewhere around 9:1.

Brandon also said that It was not uncommon, in both camps, to have a person saying "While I support X, my company forces me to use Y."

And he also has the following message, which I completely agree with:

Those of you who support the Sun Standard but who are forced to use the "C way" at work, I encourage you to take these results to your team and use them to strengthen your argument that the company is not following the majority of the industry in their code formatting. Those of you who are using the "C way", I would ask that you reconsider your stance in light of this information, and consider the value of industry standards above "personal preference".

But don't get me wrong! I do not mind using either style. After all, it's just a style, the real value is the code.

If you have a smart IDE then you can "see" the code through your prefered style without messing up the code that is in the common repository (and may be see in some other ways by others).

Which camp are you in?

Read more about Sun's official Code Conventions for the Java Programming Language.

No comments:


Creative Commons License This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 2.5 License.