4 ms·
> great error handling Go get this completely wrong! It use a tuple rather than an enum for potential errors. This means you can forget to check errors and ju
by mkehrt 11mo ago
> great error handling
Go get this completely wrong! It use a tuple rather than an enum for potential errors. This means you can forget to check errors and just use the invalid (nil?) return value from the function.
On the other hand, rust uses the Either enum to force you to handle the error. Alternatively you can use the ? operator to pass it to the calling function, which is reflected in the enclosing function's type.
- ikety 11mo agoYep Rust approach won. Pretty much every new language is adopting Result style errors and it's been adapted to plenty of existing languages. It's a product of functional programming, and for me I can't see how you would ever want to handle errors outside of the functional programming railway-oriented style. For me it's just superior.
- tczMUFlmoNk 11mo agoUmm, actually, it's specifically a coproduct of functional programming. ;-) https://en.wikipedia.org/wiki/Coproduct https://en.wikipedia.org/wiki/Coproduct
- ikety 11mo agoHa learned something
- Mond_ 11mo agoPet peeves nitpick: it's not even a tuple. Go doesn't have tuples. It just has special-cased "multiple return values", which means that it's often impossible to just stuff the return of a function call (error value and all) into any data structure to aggregate them. You just can't do without first defining a struct since tuples don't exist in Go.