Re:Go nulls and SQL
by adastra22 on Monday May 23, 2022 @04:12PM
(#31484241)
T? is just syntactic sugar for Optional/Maybe, no?
[ Parent
| on HN ]
Re:Go nulls and SQL
by shirogane86x on Tuesday May 24, 2022 @03:17AM
(#31489014)
I don't think that's quite true. It's sort of the same in how it's used, but the main difference is that T? (or T | null) is a union, and Optional/Maybe/Option is a sum type. Out of all the implementations I've seen, T? can't be nested - you can't have T??, whereas it's quite possible to have a Option<Option<T>> (and it's sometimes useful).
Roughly, yes. But that's the point: an Optional type along with static typing preventing misuse can prevent these sorts of errors entirely.
It's semantically similar but not syntactic sugar, since it is not translated to Optional or wrapper types, so it also doesn't incur the overhead of Optional.
I actually like the language support more, as it flows a lot better than the (flat)map chain you get in monadic style. Similar to async/await v.s. Future.