Closed myell0w closed 13 years ago
I prefer the !result
way because if you read from left to right I immediately read NOT result
and it's more concise. But I'm fine with either way, since the !
way has it's own drawbacks (e.g. you can overlook it more easily).
I prefer !result
since, as @eaigner said, you read it as NOT result
. But this only applies to BOOL results.
For strcmp
clearly you must never use !strcmp
, since it doesn't return BOOL but an Ordering
type LT | EQ | GT
Well, !
evaluates if the first bit is 0
or not (resp. negates the bits). So it works for int
s as well as for bool
s.
Yeah sure it works, this is C.
But !
implies that it's operating on a boolean value, not an 'enum'. So using !
makes no sense to me.
It's a smart trick that saves a few characters only to confuse people. Sure, everyone probably knows the real type of strcmp
, but not everyone knows it for obscurefunction
.
Yes that's what I meant, for BOOL !value is of course fine, but not for other data types imho. Same applies to other logical operators like && imo.
sent from phone
Am 07.07.2011 um 20:33 schrieb MSchreply@reply.github.com:
I prefer
!result
since, as @eaigner said, you read it asNOT result
. But this only applies to BOOL results.For
strcmp
clearly you must never use!strcmp
, since it doesn't return BOOL but anOrdering
typeLT | EQ | GT
Reply to this email directly or view it on GitHub: https://github.com/foundationkit/FoundationKit/issues/16#issuecomment-1524957
Same argument here. One that doesn't know what strcmp or obscurefuction returns maybe thinks it's a BOOL and gets the logic wrong, when ! is used.
As I said, I'm fine with either way. So !
for boolean types and == number
for numbers?
!
only for boolean types, proper operators (whatever they may be) for everything else
Sounds like a deal.
!, && and ||
only for BOOL, other types get converted to BOOL by using an equation
Marking this as needs final approval by @steipete
Fine with me, you guys found a consent already.
To sum it up, "if (strcmp(s1,s2) == 0)" should definitely used like this, not with the ! thing. Also every other function/var that does not return BOOL.
And like Matthias said !, && and || only for BOOL.
But on pointers, i would still allow a ! as an expection - it's an often seen context and i honestly like it :)
I don't like using logical operators for other types than BOOL, as already spotted somewhere:
What do others think? I much prefer
if (strcmp(s1,s2) == 0)
in this example, for clarity. Same goes for
vs
in my opinion.