Skip to contentSkip to conversation

CODING_STYLE: explicitly allow braceless 'else if'

PATCH Applied Avi Kivity 4 participants 4 messages Jul 25, 2011 – Jul 29, 2011

lore
Share & tools
lore

Avi Kivity

author
#0 lore raw

PATCH 1/1 CODING_STYLE: explicitly allow braceless 'else if'

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.

---
 CODING_STYLE |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)
CODING_STYLE +4 -0
index 5ecfa22..6e61c49 100644
@@ -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:
 
Signature · 1 line
1.7.5.3
Acked-by on v1 1/1
#1 lore raw
Quoted 35 lines · Avi Kivity

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 {
       ...
   }

Quoted 3 lines

which is more readable.

Quoted 23 lines

---
 CODING_STYLE |    4 ++++

 1 files changed, 4 insertions(+), 0 deletions(-)
CODING_STYLE +4 -0
index 5ecfa22..6e61c49 100644
@@ -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

#2 lore raw
Quoted 36 lines · Blue Swirl
Quoted 35 lines · Avi Kivity

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 {
       ...
   }

Quoted 5 lines
Quoted 3 lines

which is more readable.

Yes please, I use this too.

Stefan

#3 lore raw
In reply to Avi Kivity
Quoted 35 lines · Avi Kivity

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 {
         ...
     }
Quoted 3 lines

which is more readable.

Applied. Thanks.

Regards,

Anthony Liguori

Quoted 19 lines
---
  CODING_STYLE |    4 ++++
  1 files changed, 4 insertions(+), 0 deletions(-)
CODING_STYLE +4 -0
index 5ecfa22..6e61c49 100644
@@ -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: