so i know that it's modern to hate exceptions in programming languages, but what are the alternatives besides obsessively checking every return value? this includes monads which are just fancily obsessively checking return values while wearing a top hat and monocle

@eniko I gather the Rust Way is to have a return value that can be either an error or a value (a "Result"). The language then forces you to handle it (you can't pass a Result<foo, err> where a foo is needed), but gives you robust ergonomics on how to handle it, including:

foo().unwrap() (to make it crash if there's an error)
match foo() (a switch on steroids that forces you to handle both possibilities)
foo()? to bubble up the error and otherwise give you the value

In my limited experience that works quite well.

@bean yeah. that's a monad. that's just return value checking with top hats

Follow

@eniko @bean Hm. To me it feels more like exception handling, at least when using the question mark operator.

But with the benefit that there are compact, inline ways of (selectively) intercepting those errors, and that they have a value representation (which is particularly useful when you need to represent an operation that *partly* failed, like a batch operation). That's something I miss in eg. JS.

(Also I think a lot of the hate for exceptions is bandwagoning and only a very small part of it is based in the genuine criticisms, tbh.)

· · Web · 0 · 0 · 1
Sign in to participate in the conversation
Pixietown

Small server part of the pixie.town infrastructure. Registration is closed.