Re:What If I Don't Actually Like My Users? (2008)
by metaphor on Friday June 03, 2016 @12:18AM
(#11828258)
Reminds me of a comment included in code that I wrote a couple weeks back:
I deliberated with my inner voice for a minute on whether to include a comment or not. Ended up including the above thinking 18 !strcmp() statements looked strangely illogical in context even after just writing it.
[ Parent
| on HN ]
Re:What If I Don't Actually Like My Users? (2008)
by MaulingMonkey on Friday June 03, 2016 @07:07AM
(#11829567)
I always go with strcmp(...) == 0 instead of !strcmp(...).
This better reinforces my mental model of it (like many comparison functions) having 3 possible return values: <0, =0, or >0. !strcmp(...) may be terser, but it is illogical in that logical not isn't an operator. I dig using it on booleans, or "booleanish" values (null vs non-null pointers), but this conceptual tri-state isn't even "booleanish". But C didn't have a proper bool type for awhile, and C++ inherited it's baggage, so they'll compile it.
Meanwhile C# doesn't even think my "booleanish" tests are logical enough to allow to compile - no null reference tests with "operator!" for me.