mirror of
https://github.com/git/git.git
synced 2024-10-22 11:18:17 +02:00
Merge branch 'jk/coding-guidelines-update'
Developer doc update. * jk/coding-guidelines-update: CodingGuidelines: clarify multi-line brace style
This commit is contained in:
commit
a92aae5b18
@ -206,11 +206,38 @@ For C programs:
|
|||||||
x = 1;
|
x = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
is frowned upon. A gray area is when the statement extends
|
is frowned upon. But there are a few exceptions:
|
||||||
over a few lines, and/or you have a lengthy comment atop of
|
|
||||||
it. Also, like in the Linux kernel, if there is a long list
|
- When the statement extends over a few lines (e.g., a while loop
|
||||||
of "else if" statements, it can make sense to add braces to
|
with an embedded conditional, or a comment). E.g.:
|
||||||
single line blocks.
|
|
||||||
|
while (foo) {
|
||||||
|
if (x)
|
||||||
|
one();
|
||||||
|
else
|
||||||
|
two();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (foo) {
|
||||||
|
/*
|
||||||
|
* This one requires some explanation,
|
||||||
|
* so we're better off with braces to make
|
||||||
|
* it obvious that the indentation is correct.
|
||||||
|
*/
|
||||||
|
doit();
|
||||||
|
}
|
||||||
|
|
||||||
|
- When there are multiple arms to a conditional and some of them
|
||||||
|
require braces, enclose even a single line block in braces for
|
||||||
|
consistency. E.g.:
|
||||||
|
|
||||||
|
if (foo) {
|
||||||
|
doit();
|
||||||
|
} else {
|
||||||
|
one();
|
||||||
|
two();
|
||||||
|
three();
|
||||||
|
}
|
||||||
|
|
||||||
- We try to avoid assignments in the condition of an "if" statement.
|
- We try to avoid assignments in the condition of an "if" statement.
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user