Mandatory use of braces

前端 未结 21 2604
旧时难觅i
旧时难觅i 2021-02-12 23:26

As part of a code standards document I wrote awhile back, I enforce \"you must always use braces for loops and/or conditional code blocks, even (especially) if they\'re only one

21条回答
  •  没有蜡笔的小新
    2021-02-13 00:02

    I enforce this to a point, with minor exceptions for if statements which evaluate to either return or to continue a loop.

    So, this is correct by my standard:

    if(true) continue;
    

    As is this

    if(true) return;
    

    But the rule is that it is either a return or continue, and it is all on the same line. Otherwise, braces for everything.

    The reasoning is both for the sake of having a standard way of doing it, and to avoid the commenting problem you mentioned.

提交回复
热议问题