Which is clearer form: if(!value) or if(flag == value)?

后端 未结 19 2710
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-23 19:07

I understand this is a subjective question, so I apologize if it needs to be closed, but I feel like it comes up often enough for me to wonder if there is a general preferen

19条回答
  •  借酒劲吻你
    2020-12-23 19:52

    I don't think it's all that subjective. I have never seen it recommended in the longer form. Actually all the books and coding guides and "How to be a good programmer" HowTos I've read discourage it.

    It falls in the same category as

    if (value) {
      return true;
    } else {
      return false;
    }
    

    OTOH, all the answers given here make my first statement kinda equal not true.

提交回复
热议问题