|
Programming Paradigms and Useful Features |
SiegeLord
Member #7,827
October 2006
|
From my POV, algebraic datatypes have solved the null problem. E.g. in Rust you can use the Option<T> to wrap a type T. Option<T> has two possible states None and Some(T). If it's None, then it contains no value (the memory associated with T is undefined, possibly uninitialized). Additionally, you cannot get a T out of Option<T> if it's None. If it is Some(T) then it wraps a valid instance of T that you can extract with the guarantee that it is valid. I.e. null is treated differently from the valid instance of T on a type level. In principle you can distinguish multiple None states if you wanted, but usually a single None is sufficient for all the cases Kibiz0r mentioned. "For in much wisdom is much grief: and he that increases knowledge increases sorrow."-Ecclesiastes 1:18 |
J-Gamer
Member #12,491
January 2011
|
SiegeLord said: From my POV, algebraic datatypes have solved the null problem. E.g. in Rust you can use the Option<T> to wrap a type T. Option<T> has two possible states None and Some(T). If it's None, then it contains no value (the memory associated with T is undefined, possibly uninitialized). Additionally, you cannot get a T out of Option<T> if it's None. If it is Some(T) then it wraps a valid instance of T that you can extract with the guarantee that it is valid. I.e. null is treated differently from the valid instance of T on a type level. In C++ you have a similar thing in boost: boost::optional<T>. " There are plenty of wonderful ideas in The Bible, but God isn't one of them." - Derezo |
|
|