Patchwork CODING_STYLE: explicitly allow braceless 'else if'

login
register
mail settings
Submitter Avi Kivity
Date July 25, 2011, 3:55 p.m.
Message ID <1311609353-28365-1-git-send-email-avi@redhat.com>
Download mbox | patch
Permalink /patch/106710/
State New
Headers show

Comments

Avi Kivity - July 25, 2011, 3:55 p.m.
It's already allowed by the example; there are about 1800 instances in the
tree; and disallowing it would lead to

    if (a) {
        ...
    } else {
        if (b) {
            ...
        } else {
            if (c) {
                ...
            } else {
                if (d) {
                    ...
                } else {
                    ...
                }
            }
        }
    }

instead of

    if (a) {
        ...
    } else if (b) {
        ...
    } else if (c) {
        ...
    } else if (d) {
        ...
    } else {
        ...
    }

which is more readable.

Signed-off-by: Avi Kivity <avi@redhat.com>
---
 CODING_STYLE |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)
Blue Swirl - July 25, 2011, 5 p.m.
On Mon, Jul 25, 2011 at 6:55 PM, Avi Kivity <avi@redhat.com> wrote:
> It's already allowed by the example; there are about 1800 instances in the
> tree; and disallowing it would lead to
>
>    if (a) {
>        ...
>    } else {
>        if (b) {
>            ...
>        } else {
>            if (c) {
>                ...
>            } else {
>                if (d) {
>                    ...
>                } else {
>                    ...
>                }
>            }
>        }
>    }
>
> instead of
>
>    if (a) {
>        ...
>    } else if (b) {
>        ...
>    } else if (c) {
>        ...
>    } else if (d) {
>        ...
>    } else {
>        ...
>    }
>
> which is more readable.
>
> Signed-off-by: Avi Kivity <avi@redhat.com>

Acked-by: Blue Swirl <blauwirbel@gmail.com>

> ---
>  CODING_STYLE |    4 ++++
>  1 files changed, 4 insertions(+), 0 deletions(-)
>
> diff --git a/CODING_STYLE b/CODING_STYLE
> index 5ecfa22..6e61c49 100644
> --- a/CODING_STYLE
> +++ b/CODING_STYLE
> @@ -68,6 +68,10 @@ keyword.  Example:
>         printf("a was something else entirely.\n");
>     }
>
> +Note that 'else if' is considered a single statement; otherwise a long if/
> +else if/else if/.../else sequence would need an indent for every else
> +statement.
> +
>  An exception is the opening brace for a function; for reasons of tradition
>  and clarity it comes on a line by itself:
>
> --
> 1.7.5.3
>
>
Stefan Hajnoczi - July 26, 2011, 6:02 a.m.
On Mon, Jul 25, 2011 at 6:00 PM, Blue Swirl <blauwirbel@gmail.com> wrote:
> On Mon, Jul 25, 2011 at 6:55 PM, Avi Kivity <avi@redhat.com> wrote:
>> It's already allowed by the example; there are about 1800 instances in the
>> tree; and disallowing it would lead to
>>
>>    if (a) {
>>        ...
>>    } else {
>>        if (b) {
>>            ...
>>        } else {
>>            if (c) {
>>                ...
>>            } else {
>>                if (d) {
>>                    ...
>>                } else {
>>                    ...
>>                }
>>            }
>>        }
>>    }
>>
>> instead of
>>
>>    if (a) {
>>        ...
>>    } else if (b) {
>>        ...
>>    } else if (c) {
>>        ...
>>    } else if (d) {
>>        ...
>>    } else {
>>        ...
>>    }
>>
>> which is more readable.
>>
>> Signed-off-by: Avi Kivity <avi@redhat.com>
>
> Acked-by: Blue Swirl <blauwirbel@gmail.com>

Yes please, I use this too.

Stefan
Anthony Liguori - July 29, 2011, 2:37 p.m.
On 07/25/2011 10:55 AM, Avi Kivity wrote:
> It's already allowed by the example; there are about 1800 instances in the
> tree; and disallowing it would lead to
>
>      if (a) {
>          ...
>      } else {
>          if (b) {
>              ...
>          } else {
>              if (c) {
>                  ...
>              } else {
>                  if (d) {
>                      ...
>                  } else {
>                      ...
>                  }
>              }
>          }
>      }
>
> instead of
>
>      if (a) {
>          ...
>      } else if (b) {
>          ...
>      } else if (c) {
>          ...
>      } else if (d) {
>          ...
>      } else {
>          ...
>      }
>
> which is more readable.
>
> Signed-off-by: Avi Kivity<avi@redhat.com>

Applied.  Thanks.

Regards,

Anthony Liguori

> ---
>   CODING_STYLE |    4 ++++
>   1 files changed, 4 insertions(+), 0 deletions(-)
>
> diff --git a/CODING_STYLE b/CODING_STYLE
> index 5ecfa22..6e61c49 100644
> --- a/CODING_STYLE
> +++ b/CODING_STYLE
> @@ -68,6 +68,10 @@ keyword.  Example:
>           printf("a was something else entirely.\n");
>       }
>
> +Note that 'else if' is considered a single statement; otherwise a long if/
> +else if/else if/.../else sequence would need an indent for every else
> +statement.
> +
>   An exception is the opening brace for a function; for reasons of tradition
>   and clarity it comes on a line by itself:
>

Patch

diff --git a/CODING_STYLE b/CODING_STYLE
index 5ecfa22..6e61c49 100644
--- a/CODING_STYLE
+++ b/CODING_STYLE
@@ -68,6 +68,10 @@  keyword.  Example:
         printf("a was something else entirely.\n");
     }
 
+Note that 'else if' is considered a single statement; otherwise a long if/
+else if/else if/.../else sequence would need an indent for every else
+statement.
+
 An exception is the opening brace for a function; for reasons of tradition
 and clarity it comes on a line by itself: