Results 1 to 7 of 7
- 05-21-2012, 05:19 PM #1
Senior Member
- Join Date
- Apr 2012
- Posts
- 115
- Rep Power
- 0
Which is the more popular format for braces and what is your preference?
I was tought to line my braces up like so
but I see this form is common, although I find it more difficult to readJava Code:public class Animal { public void noise() { System.out.println("I want some tea"); } }
I want to ask those with experience what they think is more common and what tone is likely to find in industryJava Code:public class Animal_61 { public void noise(){ System.out.println("Animals dont make noise"); } }Legend has it the moderators and senior members of java-forums.org were able to code skyrim using only 701 lines of java... or so the legend goes.
- 05-21-2012, 05:35 PM #2
Re: Which is the more popular format for braces and what is your preference?
It's really up to you. I doubt anybody is going to begrudge you this, especially because IDEs can auto-indent however you want.
But the standard code conventions go with the second way: Code Conventions for the Java Programming Language: 7. Statements
"The opening brace should be at the end of the line that begins the compound statement; the closing brace should begin a line and be indented to the beginning of the compound statement."
I would do whatever you're most comfortable with, and if you don't have a preference, go with the standard style. And both of those (your preference and the standard conventions) can be overruled if you work at a place that micromanages you to the point of specifying where brackets should go.How to Ask Questions the Smart Way
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!
- 05-21-2012, 06:00 PM #3
Moderator
- Join Date
- Apr 2009
- Posts
- 10,481
- Rep Power
- 16
Re: Which is the more popular format for braces and what is your preference?
Industry will have a code format style embedded into its IDE, which will "correct" whatever formatting "mistakes" you might make.
At least that's been the case at the last 4 places I've been at.Please do not ask for code as refusal often offends.
- 05-21-2012, 06:19 PM #4
Re: Which is the more popular format for braces and what is your preference?
I by far prefer the second form you provided, and don't personally know anyone other than students early into their programming courses who use the former. I don't mean that as an insult to anyone, as it really is preference, but in practice, the first form adds a ton of whitespace. When your programs get large and deep, all the whitespace can make it really difficult to figure out what level of nesting you're in.
This is also a matter of preference, but anything other than [comments or formatting for cleanliness] that adds a lot of in-line whitespace can make the logic difficult to follow.
The second form looked alien to me at first (as I learned the first way) but I decided to try it for a week, and never looked back.
Consistent and clean code is more important than anything else though, so regardless of your style, as long as you stick to it, it will give you the best result.
- 05-21-2012, 06:21 PM #5
Senior Member
- Join Date
- Apr 2012
- Posts
- 115
- Rep Power
- 0
Re: Which is the more popular format for braces and what is your preference?
Thanks guys, the reason I asked this is because I find it difficult to read code the second way, I wonder if IDEs can converted between the two? for example if I was a programmer could I auto format it my way, do my job, then when I'm done autoformat back?
actually, I bet with more experience looking at code it probably wont matter.Legend has it the moderators and senior members of java-forums.org were able to code skyrim using only 701 lines of java... or so the legend goes.
- 05-21-2012, 06:27 PM #6
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,413
- Blog Entries
- 7
- Rep Power
- 17
Re: Which is the more popular format for braces and what is your preference?
When people rob a bank they get a penalty; when banks rob people they get a bonus.
- 05-21-2012, 06:33 PM #7
Re: Which is the more popular format for braces and what is your preference?
How to Ask Questions the Smart Way
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!
Similar Threads
-
Why eclipse is more popular?
By Callofdudey in forum New To JavaReplies: 3Last Post: 10-03-2011, 03:12 PM -
How to search for most popular topics among documents
By pisod in forum LuceneReplies: 1Last Post: 05-03-2011, 10:11 AM -
is android that popular?
By clydedoris in forum AndroidReplies: 2Last Post: 07-12-2010, 12:14 PM -
Right-side for left curly braces
By zweibieren in forum AWT / SwingReplies: 5Last Post: 11-02-2009, 08:08 AM -
My Preference Dialog
By schuetzejanett in forum EclipseReplies: 3Last Post: 08-10-2007, 10:48 AM


2Likes
LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks