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

后端 未结 19 2748
爱一瞬间的悲伤
爱一瞬间的悲伤 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:40

    I favour the if (!value) style at least for evaluating variables or common properties like Page.IsPostback and the like. For anything more complex I tend to parenthesise the expression like thus:

    if (!(SomeType.SomeProperty.CallingAMethod(input).GetSomething.BooleanProperty))
    

    Just to draw a little more attention to it.

    All in all, it's an argument for Perl-style unless and until keywords.

提交回复
热议问题