From patchwork Mon Oct 26 20:03:26 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Aurelien Jarno X-Patchwork-Id: 36933 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 079E4B7BC0 for ; Tue, 27 Oct 2009 07:04:07 +1100 (EST) Received: from localhost ([127.0.0.1]:55826 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1N2VnQ-0006Hw-0S for incoming@patchwork.ozlabs.org; Mon, 26 Oct 2009 16:04:04 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1N2Vmw-0006G3-Ld for qemu-devel@nongnu.org; Mon, 26 Oct 2009 16:03:34 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1N2Vmv-0006Ez-Mt for qemu-devel@nongnu.org; Mon, 26 Oct 2009 16:03:34 -0400 Received: from [199.232.76.173] (port=55480 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1N2Vmv-0006Et-JN for qemu-devel@nongnu.org; Mon, 26 Oct 2009 16:03:33 -0400 Received: from hall.aurel32.net ([88.191.82.174]:43381) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1N2Vmv-0000Ox-12 for qemu-devel@nongnu.org; Mon, 26 Oct 2009 16:03:33 -0400 Received: from [2002:52e8:2fb:1:21e:8cff:feb0:693b] (helo=volta.aurel32.net) by hall.aurel32.net with esmtpsa (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.69) (envelope-from ) id 1N2Vmp-00041p-Nq; Mon, 26 Oct 2009 21:03:27 +0100 Received: from aurel32 by volta.aurel32.net with local (Exim 4.69) (envelope-from ) id 1N2Vmo-0005cD-Hq; Mon, 26 Oct 2009 21:03:26 +0100 Date: Mon, 26 Oct 2009 21:03:26 +0100 From: Aurelien Jarno To: qemu-devel@nongnu.org Subject: Re: [Qemu-devel] [PATCH] CODING_STYLE: don't allow non-indented statements after if/else blocks Message-ID: <20091026200326.GA9669@volta.aurel32.net> References: <20091026062637.GA21562@volta.aurel32.net> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Mailer: Mutt 1.5.18 (2008-05-17) User-Agent: Mutt/1.5.18 (2008-05-17) X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6 (newer, 3) Cc: Blue Swirl X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org On Mon, Oct 26, 2009 at 06:02:52PM +0200, Blue Swirl wrote: > On Mon, Oct 26, 2009 at 8:26 AM, Aurelien Jarno 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 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 --- 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");