diff --git a/docs/CODING_STYLE.md b/docs/CODING_STYLE.md index dc4188665..5ffdaf6df 100644 --- a/docs/CODING_STYLE.md +++ b/docs/CODING_STYLE.md @@ -5,18 +5,48 @@ Basic statements: ```c++ -void global_function(int arg1, int arg2, - int arg3, ...) +void global_function(int arg1, + const int arg2, // You can use "const" preferably + const int arg3, ...) { int value; const int constValue = 0; + // We prefer to use "var = (condition ? ...: ...)" instead of + // "var = condition ? ...: ...;" to make clear about the + // ternary operator limits. + int conditionalValue1 = (condition ? 1: 2); + int conditionalValue2 = (condition ? longVarName: + otherLongVarName); + + // If a condition will return, we prefer the "return" + // statement in its own line to avoid missing the "return" + // keyword when we read code. + if (condition) + return; + + // You can use braces {} if the condition has multiple lines + // or the if-body has multiple lines. + if (condition1 || + condition2) { + return; + } + if (condition) { ... + ... + ... } + // We prefer to avoid whitespaces between "var=initial_value" + // or "var