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

  • From: Oliver Tappe <zooey@xxxxxxxxxxxxxxx>
  • To: haiku-development@xxxxxxxxxxxxx
  • Date: Tue, 08 Feb 2011 13:08:12 +0100

On 2011-02-08 at 12:13:12 [+0100], Ingo Weinhold <ingo_weinhold@xxxxxx> wrote:
> On 2011-02-08 at 10:07:56 [+0100], Oliver Tappe <zooey@xxxxxxxxxxxxxxx>
> wrote:
[ ... ]
> > From my POV, if readability is the goal, I'd go with the brace style we 
> > use
> > for 'case' already:
> > 
> > if (some condition which does not fit in one line
> >     && extends to the next line)
> > {
> >     do_something();
> > }
> 
> That's indeed the easiest to read. That downside is that, since, for
> consistency, one would that style also in case of single-line conditions and
> "else" blocks, it's using up quite a bit more space. Which IMO decreases
> readability again, as less can be displayed in a window at once. Besides I'd
> be strictly against such a drastic change at this point.

Sure, I wasn't under the impression that I could push this through ;-) 

> Regarding "case", that's a different case, since the braces don't have to do
> anything with the label. One could put the block anywhere as long as it fits
> the variable scoping needs.

I don't think it's necessarily different: comments alongside a single-line 
statement after an if require braces already, so we do not let the compiler's 
necessities dictate if/where we put braces. So one could argue that having 
the brace on the same line as the case label for improved visual consistency 
makes sense. 
All I'm saying here is that I think there is no clear reasoning behind *all* 
those rules, they just are the result of what we seem to like best.

> > From the other two, I agree that the variant with braces is slightly 
> > easier
> > to read, but so far I have never come across a coding style that required
> > braces for multi-line conditions (never mind where the braces go).
> > 
> > So I guess if we require braces for multi-line conditions, we should 
> > expect
> > that new devs will find that rule a bit peculiar/awkward.
> > 
> > But readability has to be weighed against consistency of our coding style
> > and
> > I wouldn't want to introduce variations for each and every statement kind
> > just because it reads slighty better in a particular case.
> > Since every new dev has to memorize the specialties of our style, I think
> > it'd be wise to only introduce special rules for stuff we can't really 
> > live
> > without.
> > 
> > I could live without a special rule for multi-line conditions, so I 
> > suggest
> > to stick with using braces only for multiple-line blocks following a
> > condition. We'd need to clarify that in our styleguide, too.
> 
> Well, "use braces in all cases but trivial, non-wrapped if/else/while/do/for
> statements" is at least as simple a rule.

Fine by me, too. Though I'm not sure we are currently using this:

        do
                x--;
        while (x > 1);

Or are we?

cheers,
        Oliver

Other related posts: