4 ms·
In Smalltalk it is called nil. nil is an instance of the class UndefinedObject. In principle you could subclass UndefinedObject. But what is interesting is tha
by galaxyLogic 7y ago
In Smalltalk it is called nil. nil is an instance of the class UndefinedObject. In principle you could subclass UndefinedObject. But what is interesting is that you can add more instance methods to the class UndefinedObject so you could define the method #isNil for instance which could be defined also for all objects, but differently
- perl4ever 7y agoI never learned Objective-C, but I just read that in that language: "NULL is a void *, nil is an id, and Nil is a Class pointer" ...and apparently there is also NSNull. https://nshipster.com/nil/ https://nshipster.com/nil/
- fingerlocks 7y agoFascinating. I wrote objective-c for years and cannot recall ever encountering the proper-noun form of Nil. The other three are quite common.
- 33degrees 7y agoIn Ruby, nil is a singleton instance of NilClass, and defines #nil?, as well as methods to cast to different types e.g. nil.to_a == []. Rails goes a bit further and adds #blank?, which is handy for things that might be nil or empty strings.
- galaxyLogic 7y agoIn JavaScript there's a distinction between 'null' and 'undefined'. You can pick your own semantics for them but I think 'undefined' more or less means "not known" while null means "known not to exist".
- Vanit 7y agoAgreed, but just wanted to add the context that you get undefined values by trying to access uninitialised things such as out of bounds array elements, get on a map-like object with a key that's yet to be set, unset properties on a object, return value of a function that returns void, etc.