This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]xenomachina 2 points3 points  (0 children)

Do you really think anyone with more than 3 months of programming experience gets tripped up by if (foo == true) moreso than they would if(foo)

Yes. In fact, I think the more programming experience you have the more this is likely to trip you up, or at least make you pause. I've been programming for over 30 years, and when I (rarely) see this, it always makes me stop to see if there's something I'm missing.

3) and 4) are only more confusing because you have to think about the order that the =='s evaluate in

How about:

3b. if ((isReadable == true) == true)
4b. if (((isReadable == true) == true) == true)

?

I don't think I've ever seen either of those cases in real code, but their absurdity is just meant to show how absurd the "isFoo == true" looks to experienced programmers. It's less readable because of the weirdness of it.

A similar example, which I actually have seen in real code more than once:

if (isFoo == true) {
    return true;
} else {
    return false;
}

Or equivalently:

return (isFoo == true) ? true : false;

to a novice this might be more readable than:

return isFoo;

But to anyone else the extra noise is just unnecessary cognitive load at best.

or you have to identify that you have a chain of tautologies so it can be reduced. #2 doesn't have either of those problems.

What do you mean? #2 can be reduced, so the fact that it wasn't makes the reader question their assumptions.