Should I use `!IsGood` or `IsGood == false`?

后端 未结 30 2402
礼貌的吻别
礼貌的吻别 2020-12-02 19:49

I keep seeing code that does checks like this

if (IsGood == false)
{
   DoSomething();
}

or this

if (IsGood == true)
{
   D         


        
30条回答
  •  春和景丽
    2020-12-02 20:40

    We tend to do the following here:

    if(IsGood)
    

    or

    if(IsGood == false)
    

    The reason for this is because we've got some legacy code written by a guy that is no longer here (in Delphi) that looks like:

    if not IsNotGuam then
    

    This has caused us much pain in the past, so it was decided that we would always try to check for the positive; if that wasn't possible, then compare the negative to false.

提交回复
热议问题