5 ms·
>Is it worse than exceptions? No, but "is it worse than the very worst possible option" isn't a good standard to use. >Compared to? ADTs. >Why is that? Bec
by papsosouid 13y ago
>Is it worse than exceptions?
No, but "is it worse than the very worst possible option" isn't a good standard to use.
>Compared to?
ADTs.
>Why is that?
Because you can use the value even when an error occurred. The type system should prevent this, as is trivially done in every language with ADTs.
- thezilch 13y agoWell, it's non-obvious what we're comparing it to, so I assumed the most oft compared exceptions. In this case, when opening a file, you can go ahead and use the value and "ignore" the error. Go ahead a run either of the above examples. Notice tptacek explicitly ignores the error. This argument comes up a lot in lieu of or during talk of Generics, so it'd be best for me to defer to those discussions. Unless you or the OP have examples of hating `err` handling not yet described here, opening / reading a file in Go doesn't strike me as a place to take jabs at how errors are handled in Go.
- papsosouid 13y agoI have no idea what you are talking about. The fact that you can ignore the error, including doing so by accident, is the problem. Sum types solved this problem a very long time ago, and there is simply no reason for a language created in the last decade not to have them. It is very simple conceptually, the function should not return a value and an error, because only one of those actually is valid. So it should return a value or an error.