Re: Any way to get a warning if a non-boolean type is used in an if expression?
Re: Any way to get a warning if a non-boolean type is used in an if expression?
- Subject: Re: Any way to get a warning if a non-boolean type is used in an if expression?
- From: Quincey Morris <email@hidden>
- Date: Fri, 18 Oct 2013 11:07:03 -0700
Well, I apologize if I sounded unpleasantly critical. That wasn't the intention.
On Oct 18, 2013, at 07:50 , Jens Alfke < email@hidden> wrote: Rick did not mean to write “self.active.boolValue”. That is not the point at all. If he had remembered in the moment that ‘active’ was of type ‘NSNumber’, he would have written the proper test. His mistake was misremembering the type and assuming ‘active’ was of type ‘BOOL’ and writing the conditional that way.
I knew exactly what self.active was, and yet I still failed (in one out of half a dozen instances or so) to write "self.active.boolValue", and this cause a pretty tricky symptom that led me on quite a wild goose chase.
Um, one of these things is not like the other.
In my ideal world, bool would be a first-class citizen, and it would be an error to put a non-bool _expression_ in there (there'd be no implicit type conversion to bool).
My point (which perhaps made more sense at 2 am when I came up with it) is that the boolean-ness of 'if (x)' isn't the issue in Rick's case. In C, 'if (x)' is *exactly* equivalent to 'if (x != 0)', which is as boolean-looking a test as Rick could wish, but would be just as wrong as the original code, if 'x' was 'self.active'.
|
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden