9.3 Braces
Of the three main brace placement rules, two are acceptable, the first of which is the best:
Place braces in the same column below the keyword:
if (condition)
{
...
while (condition)
{
...
}
}
Traditional UNIX brackets The rule is that the first bracket is in the same column as the keyword, and the last bracket is in the same column as the keyword:
if (condition) {
...
while (condition) {
...
}
}
Non-principled issues that cause intense debate can be solved through compromise. Either method is acceptable, but for most people I prefer the first one. The reason is something in the field of psychological research and study.
There are more reasons to prefer the first one. If the character editor you use supports bracket matching (such as vi), the most important thing is to have a good style. Why? We say that when you have a large program and want to know where this large program ends. You first move to the opening bracket, and after pressing the button the editor will find the corresponding closing bracket, for example:
if (veryLongCondition && secondVeryLongCondition)
{
...
}
else if (...)
{
...
}
To move from one block to another just use the cursor to match your bracket keys , no need to find matching parentheses.