4 ms·
There 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?.
by atombender 10y ago
There 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".
- lobster_johnson 10y agoI know, but it's "std::ptr::null", not "std::ptr::nil", which was the point of this discussion. (Clearly it has a concept of null pointers, even if they're used in a more limited manner than other languages.)
- kibwen 10y agoBut you can't use `std::ptr::null()` in the same way that you use null in the other languages mentioned there. It's literally just there for C interop, and it's called that because that's the terminology that C uses. For finding an analogue for the typical null use case in Rust, one would use the `None` variant of the `Option` enum.
- yberreby 10y agoNitpick: `std::ptr::null()` is not just there for C interop. It's also useful when writing pure Rust unsafe code.
- Gankro 10y agoCan confirm, used null all the time in Rust. The raw pointers are important native Rust constructs, although they do skew to supporting C idioms as much as possible (e.g. `* const T` and `* mut T` is basically a worthless distinction within Rust itself).
- sdegutis 10y agoSo in other words, std::ptr::null is Rust's version of null for situations where you would actually use null in C, except in general Rust discourages trying to use it like it's C. Seems reasonable.
- rurban 10y agoAnd perl with undef vs (). undef a special symbol such as null, and () the empty list as nil. Neither nil, null, none or undef refer to (void*)NULL, they are usually a special symbol in the global symbol table. Only some languages use null/nil as NULL/0 internally.
- wcarron 10y agoHuh, didn't know it was split that way. I'd seen a couple examples in C/Java/Rust/JS/Java and assumed the vast majority of them used 'null'. Thanks for edifying!