gnustep-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [RFA]: BOOL coding standards (Was: Problemwith+numberWithBool:?)


From: Nicola Pero
Subject: Re: [RFA]: BOOL coding standards (Was: Problemwith+numberWithBool:?)
Date: Sun, 8 Feb 2004 02:40:41 +0000 (GMT)

> > IOW: C "truths" (i.e. C truth semantice) aren't implicitly converted to 
> > BOOL YES/NO.  The conversion must be made explict.
> 
> But who in his sane mind would write:
> 
> > >> [NSNumber numberWithBool: (i=256)]; => NO
> 
> instead of:
> 
>      [NSNumber numberWithBool: (i=256)!=0]; => YES
> 
> ?

It's easy to build more convincing examples.

If you follow the "BOOLs are the same as C truth values" philosophy
without thinking too much, then you could end up writing stuff like

- (BOOL) isNonEmpty
{
  return count;
}

where count is an int counting the number of items in an array.

You could think that since BOOLs work as C truth values, if count is > 0,
this is YES, if it's 0, it's NO (I'm sure you've seen enough C coders to
know they love being "clever" in that way with C truth values), so the
code should work, but unfortunately it doesn't.





reply via email to

[Prev in Thread] Current Thread [Next in Thread]