Hacker News new | ask | show | jobs
by cardanome 496 days ago
> This is why Result (or Maybe, or runExceptT, and so on in other languages) is a perfectly safe way of handling unexpected or invalid data.

They are great for handling expected errors that make sense to handle explicitly.

If you try to wrap up any possible error that could ever happen in them you will generate horrendous code, always having to unwrap things, everything is a Maybe. No thanks.

I know it is tempting to think "I will write the perfect program and handle all possible errors and it will never crash" but that just results in overly complex code that ends up having more bugs and makes debugging harder. Let it crash. At the point where the error happened, don't just kick the bucket down the road. Just log the the problem and call it a day. Exceptions are an amazing tool to have for things that are.. exceptions.

1 comments

The monad and lifting fixes this problem of having to unroll the maybe type. But this is an advanced abstraction.

I actually disagree with this. Use the maybe type religiously, even without the monad because it prevents errors via exhaustive matching.

The exception should only be used if your program detects a bug.