[haiku-development] Clarifying multi-line if-clause rule

  • From: "Stephan Assmus" <superstippi@xxxxxx>
  • To: haiku-development@xxxxxxxxxxxxx
  • Date: Mon, 07 Feb 2011 23:06:50 +0100

Hi guys,

since it just came up again over at the commits list, it seems to be 
unavoidable to have some official decision on what is considered a multi-line 
if-statement. Or some may call it if-clause. That's the thing. The coding style 
guide is not exactly clear on what is considered a single line if-statement. My 
interpretation has always been that the rule is about readability. Ideally, we 
would have as few rules as possible. So in this case for example a single rule 
about simply always using parenthesis. But I think if an if-block consists of 
exactly one line of if-clause and one statement in the block, then having no 
braces is slightly easier to read:

if (some condition)
    do_something();

Slightly better than the next since less overall clutter:

if (some condition) {
    do_something();
}

This next thing is undoubtly considered a multi-line if-block:

if (some condition) {
    do_something();
    and_something_else();
}

This too:


if (some condition) {
    // Comment on the non-obvious
    do_something();
}

The question is with this one:

if (some condition which does not fit in one line
    && extends to the next line) {
    do_something();
}

if (some condition which does not fit in one line
    && extends to the next line)
    do_something();

In this case I also prefer parenthesis and think stuff is slightly easier to 
read. Some people think this is not a multi-line "if-statement", since there is 
only one statement in the block. For me, that interpretation is not in the 
spirit of the rule.

Are there any preferences either way? Maybe we can clarify the coding style 
guide based on feedback here, rather than having an actual vote. We'll see.

Best regards,
-Stephan

Other related posts: