Hacker News new | past | comments | ask | show | jobs | submit login

> 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)




Haskell 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.


I think Maybe, Either, etc. are just implemented in regular Haskell, they're not special things in the language.




Guidelines | FAQ | Support | API | Security | Lists | Bookmarklet | Legal | Apply to YC | Contact

Search: