in the sense of accidently hitting enter |
What do you mean? Like this?
1 2 3
|
else
/*accidental enter above*/statement;
|
It's only a matter of taste. I've always used the K&R, so my eyes are trained to
look for specific visual cues to find possible syntax errors.
Allman supporters argue that K&R somewhat obscures the opening brace on long
lines, but we counter with "if you can't tell the difference between these two
without looking at the brace, there's something wrong with you":
1 2 3 4 5 6 7 8 9 10 11 12 13
|
if (/*....................................................................................................................................................................*/)
statement;
if (/*....................................................................................................................................................................*/){
statement;
statement;
statement;
statement;
statement;
statement;
statement;
statement;
statement;
}
|
K&R supporters will argue that Allman tends to waste too much vertical
space on unimportant things, particularly during short blocks:
1 2 3 4 5 6 7 8
|
if (condition)
{
statement;
}
else
{
statement;
}
|
Because we are used to using indentation as the only cue for nesting, we
find the extra line for the braces focuses too much attention on something
redundant.
In reality, any style is fine as long as it's consistent within a project and
doesn't get in the way of understanding the code. I think we can all agree that
this is just
Bad:
1 2
|
if (condition) statement;
while (condition) { statement; statement;}
|
The position of braces is less important, although people hold passionate
beliefs. We have chosen one of several popular styles. Pick a style that suits
you, then use it consistently. |
-Brian Kernighan or Dennis Ritchie (I don't know which), The C Programming language