News for hackers. Stuff that matters.
Re:My Struggles with Rust by marcosdumay on Sunday May 07, 2017 @09:30AM (#14285366)
Monads are a superior form of error handling than exceptions... The only problem is that AFAIK (but I'm still learning it) Rust is missing something equivalent to Haskell's do notation.
Re:My Struggles with Rust by burntsushi on Sunday May 07, 2017 @09:37AM (#14285388)
> The only problem is that AFAIK (but I'm still learning it) Rust is missing something equivalent to Haskell's do notation.

Rust has essentially specialized do-notation for error handling called the `try!` macro, or more recently, `?`. (`try!` and `?` are exactly equivalent in today's Rust.) Actually, it does just a bit more than standard do-notation would: it also tries to convert your error value at the call site to the error type expected by the return type of the current function.

The problems posed in the OP are pedagogical ones IMO that I hope can be solved. I think the current resource on error handling in the book is good for folks who really want to dive in and figure out the complete story, but it's bad for folks who just want to write code that works without spending a couple hours doing a deep dive. So I think there's room for more targeted pedagogy here.

Re:My Struggles with Rust by hota_mazi on Sunday May 07, 2017 @10:15AM (#14285556)
> Monads are a superior form of error handling than exceptions

No, they're not, not by a long shot. As soon as you start having multiple monads returned by functions and you need to combine them, you need to introduce monad transformers and your code turns into a giant untractactable spaghetti mess.

Exceptions have issues but they are the sanest way to handle errors today.

Re:My Struggles with Rust by marcosdumay on Sunday May 07, 2017 @12:11PM (#14286109)
Well, if you start doing more with monads than error handling, you will have complex interactions between them.

They are still superior for error handling, exceptions would have a more complex interaction with them.

Re:My Struggles with Rust by placeybordeaux on Sunday May 07, 2017 @12:28PM (#14286180)
I honestly found error codes in go to be pretty pragmatic. You pay a small cost on the writing side, but it's very clear and straight forward.