Re: coding style for long conditions

David Brownell
2007-04-06T22:05:49Z

On Friday 06 April 2007 2:38 pm, Roland Dreier wrote:
> [I can't believe I'm stepping into an indentation flamewar, but here goes...]

At least you weren't the target of attacks there ... for daring to
actually follow the only published Linux style guide in that area!!

> > Please change your coding style to conform to Documentation/CodingStyle.
> >
> > *** Only indent with tabs!! ***

Having a style guide is supposed to mean, among other things, that
following it gives you "safe harbor". Sigh.

> If you have a git tree handy, you can do "git show 68380b58" and see
> that Linus himself wrote:
>
> if (get_wq_data(work) == cwq
> && work_pending(work)
> && !list_empty(&work->entry)) {

Yeah, well even the chief penguin wrangler has occasionally
admitted to human imperfections. Not exclusively related to
the 0.99 kernel series, either ... ;)

> I have to admit that I would have put the &&s at the ends of the
> previous lines rather than where Linus put them,

I approve in particular of that location: beginning of line, where
they aren't masking the intent of the condition from a casual scan.
If there's a "right" place, that's it.

In particular, if you see lots of "&&" or "||" neatly lined up it
helps you understand something about when the conditional's body
will execute without needing to read to the end of every line.

> but... egads! Linus
> put spaces before the &&s to line them up nicely!
>
> "more in the breach" and all that I guess...

Yeah, nobody likes style nazis. On the other hand, it's rather
unusual to be the target of style nazism for actually following
the style guide!! You'd think that maybe the folk objecting to
that style guide might maybe choose a more direct way to address
their particular frustrations, eh? :)

- Dave