Why the strange indentation on switch statements?

后端 未结 6 1085
太阳男子
太阳男子 2021-02-04 23:11

Why is the imho missing indentation of the \"case\" - keywords in a switch statement considered good style?

No indentation of the \"case\" keyword seems to be the defaul

6条回答
  •  傲寒
    傲寒 (楼主)
    2021-02-04 23:49

    In 4 words: no blocks, no indentation.

    Cases are not opening a block. In C or C++ you can even put variables declarations (but the initializers are not called, except for static variables, that's a pitfall) at the beginning of the switch block. You can do many weird things with switch, like Duff's device.

    Hence, as cases are just labels, indenting them does not seem that intuitive, and not indenting is the style chosen by most styles.

提交回复
热议问题