5 ms·
I'm by no means a very experienced programmer, but what was the motivation behind choosing `nil` over `null`? Seems like, from my inexperienced perspective, it
by wcarron 10y ago
I'm by no means a very experienced programmer, but what was the motivation behind choosing `nil` over `null`? Seems like, from my inexperienced perspective, it was just designed to add unneeded idiosyncratic syntax/semantics to distinguish it from Ruby and/or C.
Can't comment on anything more than that right now. Have yet to dive very deep into it.
- marcoperaza 10y agoRuby uses 'nil'.
- jrapdx3 10y agoNot a new terminology. Lisp uses "nil", which is '(), the empty list. Objective-C uses nil as a null pointer to which messages may be sent. Probably others too that I can't remember now. Many languages use "null" in similar ways. I guess it's a matter of particular syntactic conventions.
- kazinator 10y agoThe value, under conventional evaluation, of the expression '() is (), which is the empty list. This '() expression itself is the object (quote ()) which is anything but nil. The nil-()-false correspondence is only specific to the Lisp dialects which are close to the original tree. In Scheme, an empty list is indeed (), and this object also the terminating atom of a list. However, the object isn't a symbol at all, let alone the symbol nil. Moreover, the object isn't a Boolean false; Scheme has #f for that.
- careersuicide 10y agoCrystal started out as being more or less "compiled Ruby" (it's changed a bit since I first came across it). As such that means it uses "nil" just like Ruby does. And Ruby, being heavily inspired by Smalltalk, took "nil" from Smalltalk. You'd probably have to ask Alan Kay to get to the bottom of this.
- jasonm23 10y agoRe: Smalltalk, Alan Kay borrowed nil from Lisp. Matz (ruby) also borrowed nil from Lisp. (He was also inspired by Smalltalk.)
- red_hare 10y agoGenerally, you see NULL when the concept of nothing is represented with the byte value of nothing or 0 (e.g. C). Nil tends to be used in languages where the concept of nothing is represented by some sort of container. In lisp, it's simply the empty list (since all data lives in lists in lisp). In Ruby, it's a singleton object that inherits from the same base class as everything else. In both cases, the language is structured such that every container can easily be asked the question "Are you nil?" (as opposed to false or 0).
- atombender 10y agoThere are probably as many languages using "nil" as there are ones that call it "null". Nil: Ruby, Go, Oberon, Modula-2, Swift, various Pascal dialects, Lisp?. Null: C/C++, Java, Rust, JavaScript, Ada. Then, of course, there's Python with None.
- devmunchies 10y agoput SQL on the "null" team as well
- flukus 10y agoDepending on the sql variant, null could be more like nil.
- devmunchies 10y agoIf it varies from NULL then its not SQL compliant https://en.wikipedia.org/wiki/SQL_compliance https://en.wikipedia.org/wiki/SQL_compliance
- jack9 10y agoAlso.. Nil: Lua Null: PHP
- cderwin 10y agoFor what it's worth, Rust has both Null (for unsafe null pointers) and None (wrapping a type that may or may not exist at any given point). None is used far, far more frequently in my experience than null in rust though.
- kibwen 10y agoRust deliberately doesn't have anything in the language called "null" (there's `std::ptr::null()`, but that's for C interop). The only thing that fits the bill here is the unit type/empty tuple, `()`, which is sometimes called "nil".
- 10y ago