1TBS用于长条件表达式

Gau*_*ier 8 c standards indentation curly-brackets

重要提示:这个问题不是关于支撑风格优于另一支风格的优越性.我目前正在改变样式,以便自己评估哪一种我觉得在我的情况下效果最好,而且我喜欢Allman和1TBS一样多.

1TBS支撑样式的用户,如何在if语句和后续代码中格式化长条件?

if ((this_is_the_first_part_of_a_long_condition)
    && (the_second_part_is_shorter__wait_no_it_is_not)
    && (and_one_more_for_the_road)) {
    here_comes_the_block_code();
}
Run Code Online (Sandbox Code Playgroud)

我觉得必须有更好的方法.我目前的方法是在代码块的第一行之前添加一个空行.Allman在这种情况下看起来也不是很好,虽然在我看来更具可读性.

for循环的另一个例子:

for (int relevant_counter_variable_name = START_VALUE;
    intelligent_expression_that_may_include_the_counter_variable;
    relevant_counter_variable_update) {
    first_code_line_inside_the_block();
}
Run Code Online (Sandbox Code Playgroud)

不太好......

KNF(8个空格缩进)会有所帮助,但我想避免这种情况.我还有其他一些选择,但我想听听是否有某种标准方式.

Pau*_*ley 9

if (
    (this_is_the_first_part_of_a_long_condition)
    && (the_second_part_is_shorter__wait_no_it_is_not)
    && (and_one_more_for_the_road)
) {
    here_comes_the_block_code();
}
Run Code Online (Sandbox Code Playgroud)


Wak*_*iko 9

我继续双行缩进:

if ((this_is_the_first_part_of_a_long_condition)
        && (the_second_part_is_shorter__wait_no_it_is_not)
        && (and_one_more_for_the_road)) {
    here_comes_the_block_code();
}
Run Code Online (Sandbox Code Playgroud)