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

后端 未结 19 2749
爱一瞬间的悲伤
爱一瞬间的悲伤 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 personally like

    if ((value == false) == true) ...

    cause this is verifying that the statement value is false is actually evaluating to a boolean true...

    and, then, obviously, covering both posssibilites adds even more clarity,

    if ((value == false) == true && (value == false) != false)

    and for those of you who are real gluttons for clarity, and demand incontrovertible readability, I'd suggest

    if (((value == false) == true && (value == false) != false) == true)

提交回复
热议问题