by _ak · 14y ago · 0 comments
Consider the following code:
foo, err := strconv.ParseFloat(...)
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
foo, _ := strconv.ParseFloat(...)
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.
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).