Allegro.cc - Online Community

Allegro.cc Forums » Off-Topic Ordeals » Programming Paradigms and Useful Features

This thread is locked; no one can reply to it. rss feed Print
 1   2   3   4 
Programming Paradigms and Useful Features
SiegeLord
Member #7,827
October 2006
avatar

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
[SiegeLord's Abode][Codes]:[DAllegro5]:[RustAllegro]

J-Gamer
Member #12,491
January 2011
avatar

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
"If your body was a business, thought would be like micro-management and emotions would be like macro-management. If you primarily live your life with emotions, then you are prone to error on the details. If you over-think things all the time you tend to lose scope of priorities." - Mark Oates

 1   2   3   4 


Go to: