null nil

Language null true false
Java null true false
Python None True False
Objective-C nil, or NULL, or [NSNull null],
depending on context
C NULL anything except 0 0

Objective-C is psychotic. It’s a Smalltalk dialect built on top of C (and for the most part, it got the good bits of both and left out the bad bits). Obj-C lets you instantiate arrays like [NSArray arrayWithObjects:@"Hello", @"World", nil], using nil as an end-of-array marker because C’s varargs implementation doesn’t know how many args you passed. So it has this extra “null” object that’s not really null.


One thought on “null nil

  1. Rupert Phelps

    You can use nil about anywhere you can use null. The main difference is that you can send messages to nil, so you can use it in some places where null cant work.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s