I do not see the point of the agreement.
The reason to always use curly braces is rather weak, because it was assumed that the programmer knows the syntax of the language and knows that the if-statement without bindings applies only to the first expression following it.
if Oracle decides that “good practice” always writes an if-statement with curly braces, then why don't they just change the syntax?
My opinion:
If I write "without curly braces operator", I always put it on one line. Put in two lines this type of code is strange:
if(statement) code; // weird and ugly for me. if(statement) code; // ok for me, I often use in very short codes. // but if the code is long, so I prefer the code below. if(statement) { code; // if this makes your code clear, then ok. // But there is cases when I think the second option is better. }
I don't like agreements based on such stupid reasons.
Added: many people in this post agreed on the same thing: you have to do this in order to improve readability. But I think that doing this in order to avoid mistakes is not necessary.
Do you think you should change this code:
while(statement) { if (condition) i++; }
in it:
while(statement) { if (condition) { i++; } }
improve readability? I do not think so. This may be a more complicated if-statement. But everyone I know code this way only in simple if statements. True, the first case looks clearer.
But someone thinks that there is an opportunity for a programmer to do this:
while (statement) { if (condition) i++; statement; }
thinking that this statement will be part of if. I think there is no need to worry about this. Because if some programmer is capable of this, it would be worse.
I think that should be avoided - write without braces if-statement in two lines:
while (statement) { if (condition) i++; statement; }
or a nest decouples expressions like:
while (statement) if (condition) i++;
I agree with his penchant for mistakes, and this is often done by beginners. You should avoid writing complex if similar statements without curly braces.