aspose file tools*
The moose likes Beginning Java and the fly likes Java Style Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Java Style" Watch "Java Style" New topic
Author

Java Style

Dani Atrei
Ranch Hand

Joined: Feb 17, 2004
Posts: 73
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?


Si altas son las torres, el valor es alto - Alberti
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
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.


"I'm not back." - Bill Harding, Twister
Jeroen Wenting
Ranch Hand

Joined: Oct 12, 2000
Posts: 5093
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


42
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
A pox on thee, unbeliever!
Eddie Vanda
Ranch Hand

Joined: Mar 18, 2003
Posts: 281
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.


The nice thing about Standards is that there are so many to choose from!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Java Style