Hacker News new | ask | show | jobs
by andreareina 3412 days ago
!!a != !!b also works, but that's unwieldy.

I think maybe part of the reason is that usually you're also doing something with the value of the lhs or rhs, so you end up having to separate the cases anyway:

    if (a && !b) { frob(a); }
    else if (b && !a) { twiddle(b); }
    else { panic(); }
1 comments

You don't need to double-negate,

  !a != !b
is sufficient.