From 9eb7e0aa57c189c0b81a291079f7934a039e9f73 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Tue, 28 Jul 2009 22:54:04 +0000 Subject: discourage else after "noreturn" statements. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@77387 91177308-0d34-0410-b5e6-96231b3b80d8 --- docs/CodingStandards.html | 84 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) (limited to 'docs') diff --git a/docs/CodingStandards.html b/docs/CodingStandards.html index f66a7c2154..2fe3bdc9e2 100644 --- a/docs/CodingStandards.html +++ b/docs/CodingStandards.html @@ -43,6 +43,8 @@ Private
  • Use Early Exits and 'continue' to Simplify Code
  • +
  • Don't use "else" after a + return
  • Turn Predicate Loops into Predicate Functions
  • @@ -624,6 +626,88 @@ be a big understandability win.

    + +
    + Don't use "else" after a return +
    + +
    + +

    For similar reasons above (reduction of indentation and easier reading), + please do not use "else" or "else if" after something that interrupts + control flow like return, break, continue, goto, etc. For example, this is + "bad":

    + +
    +
    +  case 'J': {
    +    if (Signed) {
    +      Type = Context.getsigjmp_bufType();
    +      if (Type.isNull()) {
    +        Error = ASTContext::GE_Missing_sigjmp_buf;
    +        return QualType();
    +      } else {
    +        break;
    +      }
    +    } else {
    +      Type = Context.getjmp_bufType();
    +      if (Type.isNull()) {
    +        Error = ASTContext::GE_Missing_jmp_buf;
    +        return QualType();
    +      } else {
    +        break;
    +      }
    +    }
    +  }
    +  }
    +
    +
    + +

    It is better to write this something like:

    + +
    +
    +  case 'J':
    +    if (Signed) {
    +      Type = Context.getsigjmp_bufType();
    +      if (Type.isNull()) {
    +        Error = ASTContext::GE_Missing_sigjmp_buf;
    +        return QualType();
    +      }
    +    } else {
    +      Type = Context.getjmp_bufType();
    +      if (Type.isNull()) {
    +        Error = ASTContext::GE_Missing_jmp_buf;
    +        return QualType();
    +      }
    +    }
    +    break;
    +
    +
    + +

    Or better yet (in this case), as:

    + +
    +
    +  case 'J':
    +    if (Signed)
    +      Type = Context.getsigjmp_bufType();
    +    else
    +      Type = Context.getjmp_bufType();
    +    
    +    if (Type.isNull()) {
    +      Error = Signed ? ASTContext::GE_Missing_sigjmp_buf :
    +                       ASTContext::GE_Missing_jmp_buf;
    +      return QualType();
    +    }
    +    break;
    +
    +
    + +

    The idea is to reduce indentation and the amount of code you have to keep + track of when reading the code.

    + +
    -- cgit v1.2.3