by 0x457 · 3y ago · 0 comments
Realistically, it's no different, checking if something is null or None. Yeah, some languages have a lot of sugar around optional thanks to rich type systems.
Imagine the following pseudo rust code:
if let Some(x) = x {}
is not that different from
if x != null {}
Or any other type of boolean check.
I think you have to be around optional long enough to understand the benefits.
That is correct. However, what languages with null lack is a way to say "See this String here? This is actually a String - not the absence of a String".
It is nonsense to encode both A and lack-of-A as A.
My language has maybe<T>, and I have automatic "re-wrapping" (not sure if there is a better term). where
For example, with
record R { int x; }
maybe<R> r;
I can access r.x yet the type is maybe<int>.