But if I make a mistake like I mentioned previously, I could very well use err, thus not getting a compiler warning, and still also use foo, which is a whoknowswhat. It should be an Either, not two seperate return values.
>Making these specifics a criteria for decency is nothing but arrogance.
Having opinions is not arrogance. You should consider that when someone shares their opinion, they are not declaring that everyone everywhere must acknowledge it as a universal truth.
Right x = leftOrRight y
And get a runtime crash when a Left shows up, Or
Just x = justOrNone y
And crash on None.Of course it exists: don't unpack the result and ignore it or pass it along, or use it through its monadic or applicative interface (to proxy-with-transform to the caller).
a, _ := some_computation_that_may_fail()
b := f(a)
In Go, if there was an error in `some_computation_that_may_fail`, the call to `f` will be made with a undetermined value for `a` and we end up with an undetermined value for `b`. This is why I say that there is a path where we can use `a` even when we shouldn't.Compare with OCaml:
let Some a = some_computation_that_may_fail () in
let b = f a
First of all, the compiler will warn you that the pattern matching on line 1 is non-exhaustive and will give you an example of a failing case (here, it will simply be `None`). If the programmer ignores that warning and runs the program anyway and the computation executes with an error, the program will fail at the first line, and thus the second function `f` will never be called and `b` will not contain an undetermined value.I hope this clears up what I meant, I apologize that I wasn't clearer in the first place. Cheers!
Consider the following code:
If you don't handle the error (e.g. by forgetting), the compiler will show an error because you declared err, but didn't use it.If you write
instead, you deliberately choose to ignore the error.> In a decent language, you get either an error or a float, you have no way to accidently use the float if an error occurred.
Making these specifics a criteria for decency is nothing but arrogance.