Le lundi 08 février 2016 à 19:31 -0800, Michael Landis a écrit :
> I know there's a language theorist out there that thinks having typed
> Nullables confers some sort of linguistic purity, but I think it's a
> royal pain. Every function needs to know whether Nullable is
> possible from all of it's callers? What you gain in semantic purity,
> you pay for in the configuration back end. I thought the whole point
> of the language was write what you mean. Typed Nullables seem
> counter to that strategic objective.
I think one of the points of Nullable is to force you to explicitly
handle the possibility of it being NULL. For example, if LeapDay()
returns NULL, it's likely that you will have to use a different code
path in your function. If you don't and pass that NULL value to the
caller, which carries it as if it was a valid date, you'll get a
NullException somewhere down the road, typically in code which isn't
prepared to handle this at all. OTOH, if your function is documented to
return a Nullable{Date}, the caller knows that NULL can happen, and
will do something reasonably meaningful in that case.
This is the lesson from the NullPointerException nightmare in Java and
to crashes due to null pointer dereferences in C. For more details, see
e.g. the links at
https://groups.google.com/d/msg/julia-dev/WD7-vQeweJE
/Wn2VqwAOLzgJ
That said, some syntactic sugar could make things nicer to use (see for
example the null-coalescing operator in C#). But in the present case,
if you are absolutely sure the result won't be null, or don't care
about getting an immediate exception when it is, you can simply write:
d = get(LeapDay(yr))
Regards