Re:Null References: The Billion Dollar Mistake – Tony Hoare ...
by legulere on Monday May 30, 2016 @05:56AM
(#11800534)
This is e.g. what rust does. Another advantage of this is that you can also use them with types that aren't pointers (e.g. chars, integers, enums).
[ Parent
| on HN ]
Re:Null References: The Billion Dollar Mistake – Tony Hoare ...
by yxlx on Monday May 30, 2016 @08:30AM
(#11800957)
I would like to read about this. Got any links?
Re:Null References: The Billion Dollar Mistake – Tony Hoare ...
by legulere on Monday May 30, 2016 @09:07AM
(#11801112)
Option<T> is just a normal enum in Rust. Enums can also can have parameters in Rust. Those are usually called tagged union in non-rust-speak.
It's either Some(x) or None.
It has a pretty easy definition:
https://doc.rust-lang.org/std/option/enum.Option.html
Storing None for an Option<&T> as a null and Some(ref) just as the reference is an special optimisation that the rust compiler does. Usually you have a selector which tells you which variant of the enum it is.