18
Grumpy
8y

Pet peeve of the week: code with "== true" at the end of boolean expressions.

if (coin.isSilver() == true) ...

which is just as sensible as

if ((coin.isSilver() == true) == true) ...

or

if (((coin.isSilver() == true) == true) == true) ...

Comments
  • 1
    Thoroughly agree
  • 1
    Interestingly, I DO prefer

    if(somevalue == false)

    before

    if(!somevalue)

    because it's clearer. Principle: "code is write once, read many times"
  • 2
    @pardeike it is pretty easy to miss that exclamation mark, but if you're in Node.js and you're checking for null, == false won't get the job done
  • 0
    True, my code was for a typed language, in this case swift
  • 0
    == true annoys me, == false I understand.
  • 0
    Well, some languages have truthy and falsey values, like PHP. If you want to check that the method responded with false and didn't respond with something falsey, then an === is sensible. But not seen a use case for ==.
Add Comment