142 ms·
Stopped reading after the exception / result stuff. You can have both, both are useful, learn yourself some Swift maybe.
by auggierose 6y ago
Stopped reading after the exception / result stuff. You can have both, both are useful, learn yourself some Swift maybe.
- deleted 6y ago[deleted]
- k__ 6y agoI think monads are especially useful when the whole eco-system is build around it. Using promises with callback APIs gets ugly quickly. Using results with exception APIs also isnt much fun. Rust shines here because it's the default way.
- lioeters 6y agoI can see the author's point, that a throw behaves awfully like a GOTO. It can add complexity and unpredictability to the code path, especially dealing with external modules. On the other hand, there are situations in which throw/catch provides a simpler, even elegant way to handle errors. So I'd agree with you that both are useful. The author makes a good point though, and I will consider it next time whether returning errors may be more suitable, to be clear and explicit/verbose, without requiring the GOTO-like control flow.
- libria 6y agoAnother place throws are inconvenient is chaining/streams. Pseudocode: var goodStuff = listOfStuff.map(x => transform(x)) .filter(t => typeof(t.result) != Error) .map(y => handleGoodData(y)) If `transform()` threw exceptions, this whole thing aborts. But if it can return an `Error` type, we can continue processing the good ones and log the bad ones (here I ignore them for simplicity).