Are singleline if statements or if statements without braces bad practice?

前端 未结 12 2092
天涯浪人
天涯浪人 2021-01-01 17:10
if (condition) { /* do something */ }
else { /* do something */ }

if (condition)
    /* do something */
else
    /* do something */

I was told tha

12条回答
  •  离开以前
    2021-01-01 17:39

    Generally non-readable code is a bad practice. The single line is more efficient in your typing and saves line numbers but come back to it a year from now or while you're scanning for bugs and it'll make it more difficult.

    In my opinion, yes it's bad practice to have single line if statements.

    The computer doesn't really care (as far as I can tell) but you should always write your code like it's going to be maintained by a serial killer that knows where you live.

    Readable! Easily self-discernable.

提交回复
热议问题