Is it necessary to write else part in every if condition?

后端 未结 11 1626
-上瘾入骨i
-上瘾入骨i 2021-02-19 05:16

The question I asked might be closed, But i just want to know that is it necessary to write else part of every if condition. One of my senior programmer said me that \"you shoul

11条回答
  •  北海茫月
    2021-02-19 05:19

    That's a horrible idea. You end up with code of the form:

    if (something) {
        doSomething();
    } else {
    }
    

    How anyone could think that's more readable or maintainable that not having an else at all is beyond me. It sounds like one of those rules made up by people who have too much free time on their hands. Get them fired as quickly as you can, or at least move away calmly and quietly :-)

提交回复
热议问题