3 ms·
The article's example is a toy example. In a real-world example of the same approach, like this piece of highly non-idiomatic Python that still reads much like
by nine_k 7y ago
The article's example is a toy example. In a real-world example of the same approach, like this piece of highly non-idiomatic Python that still reads much like plain English [1].
> Try-Catch is simple, it doesn't require any brain cells to understand
...because you have already spent the effort to learn it.
Equally, monadic code can be quite compact and simple, once you have have spent the effort to learn a new approach.
Also, a catch clause does not give you an idea what data cause the crash, only what line. The Either-based approach allows every place to report all relevant local info; the linked code has complete error reporting.
Everything is non-idiomatic until it is. If you write JS and use Promises and `await`, you already use monadic behavior and an analog of Haskell's "do notation". Some might think that callbacks are more intuitive, though.
[1]: https://pastebin.com/wY8ZC0mP https://pastebin.com/wY8ZC0mP