[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH] CODING_STYLE: {} as in linux kernel

From: Kevin Wolf
Subject: Re: [Qemu-devel] [PATCH] CODING_STYLE: {} as in linux kernel
Date: Wed, 07 Oct 2009 16:12:58 +0200
User-agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv: Gecko/20090814 Fedora/3.0-2.6.b3.fc11 Thunderbird/3.0b3

Am 06.10.2009 21:01, schrieb Michael S. Tsirkin:
> Most people seem to hate using {} around sngle-statement blocks.
> And code isn't consistent either way. So let's change our standard
> to something most people like, and eliminate the pain source.
> Signed-off-by: Michael S. Tsirkin <address@hidden>
> ---
> The idea is to see which parts of linux kernel style we can pick without
> much transitional pain.  Let's start small, the following seems to be
> almost unanimously hated.
> index a579cb1..2e3ecba 100644
> @@ -51,19 +51,19 @@ 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:
> +If an indented block contains just one statement, it is not braced.  This
> +matches the Linux coding style.  The opening brace of a block 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) {
> +    if (a == 5)
>          printf("a was 5.\n");
> -    } else if (a == 6) {
> +    else if (a == 6) {
>          printf("a was 6.\n");
> -    } else {
> +        printf("multiply by 7 to get the answer.\n");
> +    } else
>          printf("a was something else entirely.\n");
> -    }

This is the best example of how having braces only sometimes makes
patches unreadable. All of the if/else lines are touched even though the
condition (and thus semantics) remains unchanged. Other than in patches
I really don't care much which way the code is written, but considering
that patches are not completely unimportant for us we might want to take
this into account.

But if we went for the change, please take Jamie's version and put
braces on all branches or on no branches, but don't mix.

>  An exception is the opening brace for a function; for reasons of tradition
>  and clarity it comes on a line by itself:
> @@ -75,4 +75,5 @@ and clarity it comes on a line by itself:
>  Rationale: a consistent (except for functions...) bracing style reduces
>  ambiguity and avoids needless churn when lines are added or removed.

Well, this sentence wouldn't apply anymore, so you should remove it.

> +This matches the linux coding style.
>  Furthermore, it is the QEMU coding style.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]