Mandatory use of braces

前端 未结 21 2314
旧时难觅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:06

    Wow. NO ONE is aware of the dangling else problem? This is essentially THE reason for always using braces.

    In a nutshell, you can have nasty ambiguous logic with else statements, especially when they're nested. Different compilers resolve the ambiguity in their own ways. It can be a huge problem to leave off braces if you don't know what you're doing.

    Aesthetics and readability has nothing to do it.

提交回复
热议问题