From: Roland Dreier <rdreier@cisco.com>
To: Hans Verkuil <hverkuil@xs4all.nl>
Cc: LKML <linux-kernel@vger.kernel.org>,
"v4l-dvb maintainer list" <v4l-dvb-maintainer@linuxtv.org>
Subject: Re: CodingStyle question: multiple statements on a single line
Date: Tue, 02 Sep 2008 15:34:42 -0700 [thread overview]
Message-ID: <ada7i9ufa7x.fsf@cisco.com> (raw)
In-Reply-To: <200809030021.00122.hverkuil@xs4all.nl> (Hans Verkuil's message of "Wed, 3 Sep 2008 00:20:59 +0200")
> 2) No, never use the 'if (a) b;' construction. Put 'b;' on the next line
> instead.
This is correct. Always write simple if statements as
if (a)
b;
> And in general, why is this:
>
> if (a) {
> b;
> }
>
> not accepted by the CodingStyle? (At least as I understand it)
The braces take up another line of whitespace, which means less code
fits on the screen. And in simple cases, they don't add anything.
Finally, the vast majority of the kernel leaves the braces off, so they
look funny to people who read a lot of kernel code.
And uniformity counts for a lot: most coding style rules are completely
arbitrary, but having a uniform kernel style makes reading kernel code
much easier.
Keep in mind that common sense always trumps any mechanical rule. So if
there is some case where writing
if (a) {
b;
}
is clearly easier to read than leaving the braces off, then that would
be OK.
- R.
next prev parent reply other threads:[~2008-09-02 22:34 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-09-02 22:20 CodingStyle question: multiple statements on a single line Hans Verkuil
2008-09-02 22:34 ` Roland Dreier [this message]
2008-09-02 23:50 ` Mike Isely
2008-09-03 0:23 ` Randy Dunlap
2008-09-03 12:19 ` Krzysztof Halasa
2008-09-03 18:38 ` Roland Dreier
2008-09-03 20:22 ` Lennart Sorensen
2008-09-03 12:15 ` Krzysztof Halasa
2008-09-03 6:57 ` Frans Meulenbroeks
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ada7i9ufa7x.fsf@cisco.com \
--to=rdreier@cisco.com \
--cc=hverkuil@xs4all.nl \
--cc=linux-kernel@vger.kernel.org \
--cc=v4l-dvb-maintainer@linuxtv.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.