3 ms·
Fully agree. IMO this is the same argument as "the for loop is a magic keyword" which just isn't true. Try/catch makes it _incredibly_ clear what you're trying
by cheeze 7y ago
Fully agree. IMO this is the same argument as "the for loop is a magic keyword" which just isn't true.
Try/catch makes it _incredibly_ clear what you're trying to do. Kids who graduate college and get their first real job understand what a try/catch does. A random contributor to an OSS project knows what try/catch does.
Meanwhile, I'd be willing to bet that not even 10% of programmers could actually explain what a monad is.
I'm sure there is a place for this elegant error handling, but in most codebases it seems like a pretty big complexification for not all that much benefit. Sure, the code might even be "more correct" (whatever that means), but if Samantha the intern can't pick it up rather quickly, it probably isn't all that well suited for mainstream usage.
- lmm 7y ago> IMO this is the same argument as "the for loop is a magic keyword" which just isn't true. The for loop is indeed a magic keyword, though it's less surprising/magic than try/catch; most of what for does could be done by a plain old function. > Meanwhile, I'd be willing to bet that not even 10% of programmers could actually explain what a monad is. Don't try to generalize prematurely. Considering Either on its own, it's simpler than try/catch and can replace their use cases. If you'd started with Either, try/catch would seem like the overcomplicated solution in search of a problem that it is.
- true_religion 7y agoAlmost all special purpose control syntax can be replaced by a series of function calls, but the value of syntax is clarity of intent.
- cheeze 7y ago> If you'd started with Either, try/catch would seem like the overcomplicated solution in search of a problem that it is. But we didn't start with Either, which IMO is an incredibly important distinction. Bolting things like this onto the language after the fact isn't the same as having first class support by default (like in say, Haskell)
- agentultra 7y agoHaskell doesn't have special support for Either. It's a plain old data structure with a few type classes. You can write Either in any language that supports passing functions as parameter values. It's taking the logical disjunction operator, `||` in many languages, and sticking it in a data structure. You can now pass it around like a normal JS value and combine it with other such values. The benefit of this over exceptions is that for unexceptional situations you don't end up throwing away the context of your computation if something takes the "bad path." Instead of jumping to the exception handler and losing all of your data your program can handle the situation at the site of the error where it has the most context to solve the issue. TFA wasn't advocating abandoning try/catch -- it was suggesting that for non-exceptional cases it will make your code cleaner.
- IanCal 7y agoI think Maybe, Either, etc. are just implemented in regular Haskell, they're not special things in the language.
- Fellshard 7y agoThis argument doesn't hold with me, because while try-catch is very clear in what it does, the exception-/throwing/ mechanism is not. Try-catch is only useful insofar as you know exactly what you're trying to catch. Anything else is basically undefined behaviour; a jump straight to your catch block from anywhere in the application, as far as your intuition is concerned, a far cry from the controlled nature of loops.
- RHSeeger 7y ago> I'd be willing to bet that not even 10% of programmers could actually explain what a monad is. To be fair, I don't think you need to really understand what monad is to understand Either.