4 ms·
> it is entirely possible to live without null, and languages like Rust do. It seems as though there is this common misconception that Rust does not have a con
by ibraheemdev 6y ago
> it is entirely possible to live without null, and languages like Rust do.
It seems as though there is this common misconception that Rust does not have a concept of null. Rust does have null pointers [1]! The reason many people do not see null often is because working with and dereferencing raw pointers is an unsafe operation
1: https://doc.rust-lang.org/std/ptr/fn.null.html https://doc.rust-lang.org/std/ptr/fn.null.html
- joshgev 6y ago> It seems as though there is this common misconception that Rust does not have a concept of null. I don't think that's quite relevant, though. Rust doesn't have a concept of nulls like like Java, Javascript, Python, etc do in which just about any variable might contain a value or null. Rust certainly doesn't have that.
- ibraheemdev 6y agoI would not say that it is not relevant. Raw pointers are a fundamental part of the language. It is just that Rust abstracts over them so that many users do not have to worry about them. I see your point though.
- viraptor 6y agoI don't think people mean it doesn't have a raw null pointer. Normally it's about a null object reference that you can assign to (almost) anything like Java's / c's null.
- Cyph0n 6y agoOf course Rust has a null pointer type. Otherwise, it wouldn’t really be a systems programming language :) But most users would rarely if ever need to use that type. Option<T> is how Rust deals with optional/nullable values.
- ChrisSD 6y agoNote that nowadays the preferred way to handle null pointers in APIs is the `Option<NonNull>` type. This unfortunately wasn't available in Rust 1.0. https://doc.rust-lang.org/std/ptr/struct.NonNull.html https://doc.rust-lang.org/std/ptr/struct.NonNull.html