4 ms·
!!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 y
by andreareina 10y 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(); }
- caf 10y agoYou don't need to double-negate, !a != !b is sufficient.