aspose file tools*
The moose likes Cattle Drive and the fly likes Formatting rule for braces - some specifics please. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » This Site » Cattle Drive
Bookmark "Formatting rule for braces - some specifics please." Watch "Formatting rule for braces - some specifics please." New topic
Author

Formatting rule for braces - some specifics please.

Colm Dickson
Ranch Hand

Joined: Apr 04, 2009
Posts: 89
Hello all,
A code formatting question where I cannot derive to 'when to' and 'when not to' from the style guide..

I fear I am in breach of some formatting rules when it comes to using my braces and indenting. Now, reading the style guide it recommends an indentation of 4 spaces but where it is not clear is when to indent. Using the example below, I start with the class definition, open my braces and then indent 4 spaces for my method.I have then indented for the if and so on as I go along, matching the closing braces up with the opening one. My question is wen to indent as I fear I'm doing too much indentation- Any hard and fast rules such as always indent after class name? Always for method etc..Basically..when should a next line line up with the brace before and when should an indent be used?




Thanks,

Colm
Kurt Van Etten
Ranch Hand

Joined: Sep 07, 2010
Posts: 98
What you have looks fine to me--I think you're interpreting the rules exactly as they are intended. Anything that represents a nested block of code gets indented. A lot of programmers like to put the opening brace at the end of the preceding line instead of on a line by itself, and that makes the cattle drive code look a little bit spaced out. But the indentation itself is, I think, pretty standard. (I personally agree with putting the opening brace on a line by itself, it makes it a lot easier to identify the start and end of a block of code.)
Colm Dickson
Ranch Hand

Joined: Apr 04, 2009
Posts: 89
Thanks Kurt.
 
 
subject: Formatting rule for braces - some specifics please.