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?
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.)
Joined: Apr 04, 2009
subject: Formatting rule for braces - some specifics please.