This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Java Style

 
Dani Atrei
Ranch Hand
Posts: 73
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have thought for a long while whether the question i m about to ask is worth asking or is it not. But my curiosity floods all my senses for me to ask you this: I read in a book a couple of days ago that the java convention for compounds statements is to put the opening brace directly after the, for example method declaration:
public void whyThisStyle(){
//code
}
I m used to putting both braces in a line such as:
public void whyThisStyle()
{
}
I deem it (personal taste surely)to be more readable, and however, it appears that the convention dictates suc ha personal (and trivial in a way) topic. Why is that?
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
it appears that the convention dictates suc ha personal (and trivial in a way) topic. Why is that?
Basically because if they don't, many developers will spend too much time arguing about their favorite style with the other developers. If code is written by one person and then edited by someone else with a different style, it becomes harder to read; better to have everyone on a team using the same style, regardless of what that style is.
That's true for any large project under some sort of central control, anyway. There really is no single style that everyone who programs Java follows. Sun has their own style which is used by many other companies as well, but this is not absolute. No matter what your preference, it's entirely possible you'll find yourself working with a team of people who requires you to do it differently. A good programmer should be able to adjust their style easily to meet their local community standards.
As far as which style is really better, and why - this question will never really be resolved. You can find a good recent discussion here.
 
Jeroen Wenting
Ranch Hand
Posts: 5093
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Jim Yingst:
As far as which style is really better, and why - this question will never really be resolved. You can find a good recent discussion here.

It's been resolved a long time ago, the K&R adherents just haven't caught on yet
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A pox on thee, unbeliever!
 
Eddie Vanda
Ranch Hand
Posts: 281
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think the reason a lot of programmers use the endOfLine block opening brace is that you gain a few lines. This may be contentious, but I believe any method larger that one page becomes harder to validate visually and this layout allows a few more lines of programming per page. Of course, indenting, meaningfull names and vertical spacing is vital to ease the understanding of a method.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic