• Post Reply Bookmark Topic Watch Topic
  • New Topic

Which is right place to braces in java code?  RSS feed

 
Srikanth Shreenivas
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Though Sun's coding guidelines recommends that braces should be placed at the end of line which corresponds to start of a block, however, I frequently find that convention invonvenient when I m looking at code at trying to match braces to see a particular block starts/ends.

Is it okay to deviate from this guideline and use braces the way we did traditionally in C++?
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The important thing is not which of the two bracket styles you use. The important thing for any project is that the style is agreed upon and followed conscientiously by all coders.
 
Jeroen T Wenting
Ranch Hand
Posts: 1847
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Let loose the dogs of war.

This is an eternal debate among programmers and language designers alike.
There is no technical reason inherent in the language for either (such as there is in some other languages that require block demarkation in specific columns for the compiler to recognise them), but a large number of conflicting philosophical arguments and personal preferences.

I generally use whichever style the language designers prescribed in their documentation, as that's the most likely style to be used by others using that language.
But I'm not going to change the layout of existing code if it doesn't match that style, and will adept what code I write modifying such code to use that style.

As such I invoke the wrath of all sides, none of which consider me true to the One Path
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Most recent editors allow bracket matching, to highlight both starting and ending brackets, so it's not that inconvenient.
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moreover, most editors make it really easy to format your code so that the brace structure is obvious just from the indentation. And any fellow programmers who fail to indent their code properly should simply be killed out of hand - it's really best for everyone, in most cases.
 
Campbell Ritchie
Marshal
Posts: 55772
163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Posted by Jim Yingst
killed out of hand.
I hope you are not suggesting anything quick and painless.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!