2 ms·
There is bound to be some wrangling with the returned value if the case of "something was returned" needs different treatment from "nothing was returned" in th
by limmeau 17y ago
There is bound to be some wrangling with the returned value if the case of "something was returned" needs different treatment from "nothing was returned" in the program's design.
However, I agree that
match perform_foo() with
| Some x -> do_something_with x
| None -> do_without
looks a lot less messy than
JOption<Bar> baropt = performFoo();
if(baropt.isNonempty()) {
Bar bar = baropt.getValue();
doSomethingWith(bar);
}
else {
doWithout();
}
There's just something deeply unsatisfying with a statically typed language that requires so much legalese and boilerplate as Java while still permitting surprising runtime errors in virtually every executable line of the program. Abandoning static types is one approach to the dilemma, trying to plug hole by hole is another.