From: Aurelien Jarno <aurelien@aurel32.net>
To: qemu-devel@nongnu.org
Cc: Blue Swirl <blauwirbel@gmail.com>
Subject: Re: [Qemu-devel] [PATCH] CODING_STYLE: don't allow non-indented statements after if/else blocks
Date: Mon, 26 Oct 2009 21:03:26 +0100 [thread overview]
Message-ID: <20091026200326.GA9669@volta.aurel32.net> (raw)
In-Reply-To: <f43fc5580910260902l3b2c255cgd78d67fadd88890c@mail.gmail.com>
On Mon, Oct 26, 2009 at 06:02:52PM +0200, Blue Swirl wrote:
> On Mon, Oct 26, 2009 at 8:26 AM, Aurelien Jarno <aurelien@aurel32.net> wrote:
> > Rationale: The following code is difficult to read, but allowed by the
> > current coding style.
>
> Fully agree.
>
> > +Every control flow statement is followed by a new indented and braced
> > +block; even if the block contains just one statement. The opening brace
> > +is on the line that contains the control flow statement that introduces
> > +the new block; the closing brace is on the same line as the else keyword,
> > +or on a line by itself if there is no else keyword. Example:
>
> I think an exception should be granted for "else if" case, otherwise
> the style would require braces around "if", like:
> if (a == 5) {
> printf("a was 5.\n");
> } else {
> if (a == 6) {
> printf("a was 6.\n");
> }
> } else {
> printf("a was something else entirely.\n");
> }
>
> Picking nits: "while" is a control flow statement, even in "do {}
> while" statement and then it would illegal to require a braced block
> after the "while" statement.
Good point. Please find another try below:
From: Aurelien Jarno <aurelien@aurel32.net>
Rationale: The following code is difficult to read:
if (a == 5) printf("a was 5.\n");
else if (a == 6) printf("a was 6.\n");
else printf("a was something else entirely.\n");
Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
---
CODING_STYLE | 12 +++++++-----
1 files changed, 7 insertions(+), 5 deletions(-)
diff --git a/CODING_STYLE b/CODING_STYLE
index a579cb1..c17c3f3 100644
--- a/CODING_STYLE
+++ b/CODING_STYLE
@@ -51,11 +51,13 @@ QEMU coding style.
4. Block structure
-Every indented statement is braced; even if the block contains just one
-statement. The opening brace is on the line that contains the control
-flow statement that introduces the new block; the closing brace is on the
-same line as the else keyword, or on a line by itself if there is no else
-keyword. Example:
+Every control flow statement is followed by a new indented and braced
+block, except if it is followed by another control flow statement (else
+if) or by a condition (do {} while ()); even if the block contains just
+one statement. The opening brace is on the line that contains the
+control flow statement that introduces the new block; the closing
+brace is on the same line as the else keyword, or on a line by itself
+if there is no else keyword. Example:
if (a == 5) {
printf("a was 5.\n");
--
1.6.1.3
--
Aurelien Jarno GPG: 1024D/F1BCDB73
aurelien@aurel32.net http://www.aurel32.net
next prev parent reply other threads:[~2009-10-26 20:03 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-10-26 6:26 [Qemu-devel] [PATCH] CODING_STYLE: don't allow non-indented statements after if/else blocks Aurelien Jarno
2009-10-26 16:02 ` Blue Swirl
2009-10-26 20:03 ` Aurelien Jarno [this message]
2009-10-26 20:20 ` Blue Swirl
2009-10-26 20:27 ` Aurelien Jarno
2009-10-26 21:16 ` Anthony Liguori
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=20091026200326.GA9669@volta.aurel32.net \
--to=aurelien@aurel32.net \
--cc=blauwirbel@gmail.com \
--cc=qemu-devel@nongnu.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).