3 ms·
Reminds me of a comment included in code that I wrote a couple weeks back: // ... Function strcmp() returns 0 on match, therefore, !strcmp() is TRUE on match
by metaphor 10y ago
Reminds me of a comment included in code that I wrote a couple weeks back:
// ... Function strcmp() returns 0 on match, therefore, !strcmp() is TRUE on match.
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.
- MaulingMonkey 10y agoI 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.