Re: NSNull and @""
Re: NSNull and @""
- Subject: Re: NSNull and @""
- From: Ian Joyner <email@hidden>
- Date: Sat, 11 Oct 2008 13:28:05 +1100
On 11/10/2008, at 11:58 AM, Seth Willits wrote:
On Oct 10, 2008, at 5:40 PM, Ian Joyner wrote:
I'm just trying to work out what NSNull really is in the Cocoa
context. Is it an object in Cocoa?
As I said, yes. It's truly an object. (A singleton, as well.)
Since NSNull may be a "valid" value of any other type, is it
counted as a subtype of every other type (hence the ultimate
subclass)? I think a good and simple (one that doesn't make my
brain hurt) definition of NSNull is important in order to ensure
software correctness.
Woah. Talk about brain hurt. You're thinking about this far too much.
I don't think you can think about anything too much. If one doesn't
have a clear understanding of the semantics of programming constructs
then resultant software full of bugs (I'm sure Confuscious said
something like this several thousand years ago). Perhaps that's why we
have become so test dependent – don't think, just test. Well, I'll
refrain from going further into a philosophical debate at this point.
There's no inheritance, there's no nothing. It's an object. It's
absolutely in no way different than you creating your own IJNull
class, and sticking an instance of it anywhere. It doesn't behave
any differently.
As for use, the documentation says it pretty clearly:
"The NSNull class defines a singleton object used to represent null
values in collection objects (which don’t allow nil values)."
You can't stick nil into dictionaries and arrays. So either you
stick an empty string, an NSNumber with 0, etc if those are OK, or
you can use NSNull.
So it's really a workaround for this situation. I think therefore
there are several constructs to represent the same concept of "lack of
presence" – nil, Nil, Null, and NSNull.
Sorry, but NULL values need very careful reasoning and handling. (See
C.J. Date "Database Systems" 5.6 Nulls (A Digression).) Thanks for
your insights.
Ian_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden