Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

ruby nil is similar in that it's an instance of the Nil class. though, calling a method on nil that isn't there is a common error.

I like how swift handles things. strong type system that makes it a little painful to do things unsafely. guarantees some things that make it a powerful and more safe language than objective c. I think they lost a few dynamic patterns though in the transition but that's just what i recall from a blog post and the details of it are a little fuzzy.



There is a reason why in Lisp the type of NIL is NULL and not NIL. NIL does in fact name a type also. That is different from the NULL type/class.

NULL has one instance, the object NIL. NULL isn't derived from anything; its superclass is the master superclass T.

The NIL type has an empty domain: no object is of the NIL type. (Somewhat like in C and C++, no object is of the void type, for those who like pointless C and C++ analogies that don't lead anywhere.) Furthermore, the NIL type is a subtype of every other type, the same way that T is a supertype of every other type. That is to say, every type is implicitly a supertype of nil. This goes hand in hand with the fact that the set of instances of any type is a superset of the empty set. E.g. set of integers (a type) has an empty subset (every set does), and that empty subset can be identified as the NIL type, whose domain is the empty set.


I agree, Swift's optionals are really great. But I also like Objective-C's nil: you can send messages to it and it won't do anything. That too solves a ton of problems with NULL.


What solves problem with null is if you can send messages to it, and have it do exactly what you want depending on the nature of message.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: