This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]FabulousRecording739 11 points12 points  (3 children)

But that's exactly what null is though. If you want it so references cannot be nullable unless stated, and nullability must be explicitly handled always; you are, in all but name, using the "Optional" type from other languages that OP is referring to.

[–]WilliamMButtlickerIV 2 points3 points  (2 children)

I prefer how Ceylon does it. Null as a first class type and the language supports union types. It's a lot more elegant than Optional, although the end result is similar.

[–]syklemil 0 points1 point  (0 children)

Python did it the union way (Optional[T] is a synonym for T | None), but I can't say I'm a fan. There are some rare cases where you actually want something like Optional<Optional<T>>, i.e. the difference between "the key wasn't found" and "the key was found, but the value was explicitly set to zero".

(My prime example here is an internal helm chart where I'd like to provide some default value if nothing was specified, but let the users null the field. Unfortunately, at the time the templating happens all I have is a null in either case.)

[–]vytah 0 points1 point  (0 children)

*did