• Post Reply Bookmark Topic Watch Topic
  • New Topic

Code style - next line brackets  RSS feed

 
Barry Andrews
Ranch Hand
Posts: 529
C++ Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Folks,
I'm not looking to start a debate here, but if it turns into one then that's fine too. We are starting a new Java project at our company and are now setting the coding style guidelines. One of the guidelines we would like to set is the bracket form. The Sun specs say this is correct:

But members of our team prefer this:

To us the second form is just more readable. Okay, here come the debates. :roll:

To be able to use this style we have to make a good argument for it to the manager. So I was trying to find open source projects out there that use our preferred bracket style. They are hard to find, but I managed to find 2 so far; JBoss, and Azureus BitTorrent.

Does anyone know of any other projects that use this style?

Your help is greatly appreciated!
 
Alain Boucher
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wow... you must be working for a huge stupid company my friend... if they pay you to debate on those thing... If I was the manager at your place, I would tell you to use Java Standard... You try to use java, so why you don't follow the java standards...
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Alain Boucher:
Wow... you must be working for a huge stupid company my friend... if they pay you to debate on those thing... If I was the manager at your place, I would tell you to use Java Standard... You try to use java, so why you don't follow the java standards...


Java standards? What are the Java standards? I know Sun has a standard and then there is a more strict "standard" of Sun's standard that Javaranch's Cattle Drive adheres to.

While I don't agree with the way Alain stated it, I do agree that this might not be the best thing to waste too much time on. The main goal, I feel, is not which style, but that everyone is using the same style. There are companies that use styles that aren't standard at all. But the key is all the employees are using that style.
 
Alain Boucher
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes java standard: http://java.sun.com/docs/codeconv/html/CodeConventions.doc5.html#381
 
Barry Andrews
Ranch Hand
Posts: 529
C++ Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And the debating begins!

If I was the manager at your place...

Good thing you're not!

So is someone going to tell me now that JBoss (one of the biggest and most successful open source projects) uses the WRONG coding style? I don't think so!


But the key is all the employees are using that style.

I absolutely agree! But again, I am just trying to find a few more examples of projects that do not use the "standard"
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Alain Boucher:
Yes java standard: http://java.sun.com/docs/codeconv/html/CodeConventions.doc5.html#381


I would argue that this is Sun's standard for Java. Not the Java standard. I don't believe there is such a thing as Java standard, but that's probably semantics.
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Barry Andrews:
To us the second form is just more readable.

Well, personally... I have trouble with the second form, and actually reformat complex code to the Sun standards so I can follow it. But that's me.
[ October 06, 2004: Message edited by: marc weber ]
 
Stefan Wagner
Ranch Hand
Posts: 1923
Linux Postgres Database Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why do you need conding-standards?

Perhaps if you work with different tools, in a team, and need a version-control.

I prefer the allman-style for readability (2. style), and eclipse reformats everything to my prefered style by a button-click.

If you have a mechanism, to convert all source-code before storing, your cvs-system will not mention differences in white-space, and everybody can work in his preferred style.

I wouldn't let a manager decide for my coding-style.
 
Barry Andrews
Ranch Hand
Posts: 529
C++ Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you have a mechanism, to convert all source-code before storing, your cvs-system will not mention differences in white-space, and everybody can work in his preferred style.


Do you know of a way to do this? It's true you can do CTRL+SHIFT+F in Eclipse and it will reformat your code to your style. But if it is a manual process to check out code, reformat, write some code, reformat, check back in, this will be a big pain.
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'll just throw in a vote for aligned brackets, your example 2. Personally it matches an aligned style I've used in REXX and Pascal and other languages and makes it easier to match up brackets. The only rationale I've heard for creating the original K&R style was it conserved vertical space, but I try not to make methods that are vertically challenging.

If you use Eclipse and have managers who care about this stuff, you can export one set of preferences for the code formatter and require everyone to import it. The latest Eclipse has a zillion new options in the code formatter. Way too many. Sheesh.
 
Warren Dew
blacksmith
Ranch Hand
Posts: 1332
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Barry Andrews:

But members of our team prefer this:

All members of the team, or just some of them?

If all coding members of the team prefer aligned braces - including the manager if he codes - then the manager is crazy to enforce something else. If only some of the members of the team prefer aligned braces, the manager is perfectly within his rights to make an arbitrary decision.

NASA did one study, a long time ago, that indicated that aligned braces resulted in fewer bugs, so that might be evidence that your manager would listen to. On the other hand, the reason was apparently that aligned braces made code reviews easier, so this argument might not apply if you're not doing code reviews....
 
Mike Gershman
Ranch Hand
Posts: 1272
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I wouldn't let a manager decide for my coding-style.

Even if the code can be shown either way with a button click, how about printed dcumentation, printed listings, etc.

It is the manager's job to pick standards. Quitting is always an option, but imagine listing "strict coding standards" as your reason for leaving on your next job application.
 
Jeroen Wenting
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by marc weber:

Well, personally... I have trouble with the second form, and actually reformat complex code to the Sun standards so I can follow it. But that's me.


And I have trouble with the first form and reformat complex code to adhere to the second sometimes.

Might be because I was weaned on Pascal and C++, both of which use block delimiters on their own lines (albeit not mandatory).

It makes it far easier to see the extent of a block. I just spent several hours yesterday looking to understand some code which turned out to be quite simple after a bit of reformating.

used to be formated as


Now which is easier to read?
 
Jeroen Wenting
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Mike Gershman:

Even if the code can be shown either way with a button click, how about printed dcumentation, printed listings, etc.

I've never seen a printer that couldn't print code if it had a block start on its own line...

Originally posted by Mike Gershman:

It is the manager's job to pick standards. Quitting is always an option, but imagine listing "strict coding standards" as your reason for leaving on your next job application.


It's a manager's job in things like this to approve reccomendations and maybe to make a final decision if the team can't agree.
Only in massive corporations with "standards" departments are there people whose sole job it is to make sure people do things the "standard" way whatever the standard (which they themselves with no input from the people in the trenches define) might be.

Best way is to get together a comittee from the programmers and hammer out a company standard everyone can live with.
Present that for approval to the software manager (or whatever the title of the head of development) and get it adopted as company policy.

IMO a good example to use might be the Borland conventions for Pascal and the Stroustrup conventions for C++, with parts of the Sun conventions for Java thrown in.
That will yield readable code.
And don't make them too strict. You don't want to insert things like mandatory minimum lengths for method and variable names (I've seen it).
Avoid Hungarian notation like the plague. It's used in Visual C++ and Visual BASIC because an old Microsoft employee who had great influence in the creation of those languages created it (before joining Microsoft btw) and should not be used anywhere else as it's an abomination.
 
Barry Andrews
Ranch Hand
Posts: 529
C++ Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
NASA did one study, a long time ago, that indicated that aligned braces resulted in fewer bugs


That's interesting. Is there a document somewhere? I searched on Google and on nasa.gov, but did not turn up anything.
 
Stefan Wagner
Ranch Hand
Posts: 1923
Linux Postgres Database Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Barry Andrews:


Do you know of a way to do this? (...) if it is a manual process(...), this will be a big pain.


Yes (big pain).
No (don't know a way to do this).
I'm currently not working with a cvs-system, and don't know, if it is possible, to set it up to ignore white-space and empty lines in diffs.

But together with eclipse, where you may store your preferred settings on an usb-stick, and carry it with you, it would be a great step in mans freedom, if someone get's an solution to this - everybody may code the way he likes.

The last problem will be the XP-pair-programmers, looking at the same screen.
They need a special, intelligent form of eyeglasses, formatting on the fly

Jeroen:
Does Visual Basic have dynamic type bindings?
I'm asking, because prefix-notations make some sense, when you don't have static type checking.
And no object-inspector or class-browser, or how it is called, to show you the type on the fly.

Mike: Perhaps I would try to drive the management insane, by asking for special cases and rules for every little piece of code.
Ask for a written specification of formatting to learn it, and search for conflicts...
 
Mike Gershman
Ranch Hand
Posts: 1272
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mike: Perhaps I would try to drive the management insane, by asking for special cases and rules for every little piece of code.

I take it that in Germany it's still almost impossible to fire someone for a bad attitude and employees can appeal low salary increases to the works council.

Is it really worth trading whatever credit you earned with management for quality work for the momentary satisfaction of "driving ... management insane" over where to place left braces?

Then when the next down-sizing comes around ...
 
Stefan Wagner
Ranch Hand
Posts: 1923
Linux Postgres Database Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Would a surgeon let a manager decide, how to hold the scalpel?
I guess not.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!