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

后端 未结 30 2475
礼貌的吻别
礼貌的吻别 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:56

    From the answers so far, this seems to be the consensus:

    1. The short form is best in most cases. (IsGood and !IsGood)
    2. Boolean variables should be written as a positive. (IsGood instead of IsBad)
    3. Since most compilers will output the same code either way, there is no performance difference, except in the case of interpreted languages.
    4. This issue has no clear winner could probably be seen as a battle in the religious war of coding style.

提交回复
热议问题