4 ms·
Conceptually that makes sense, but having to explicitly check the type of the return value every time is just hideous.
by TillE 14y ago
Conceptually that makes sense, but having to explicitly check the type of the return value every time is just hideous.
- pacala 14y agoUhm, then don't code in Go?
- sirclueless 14y agoYou can ignore errors in Go by assigning them to _. You can't if your return value is sometimes an Error.
- ori_b 14y agoYou could implement something like lvalue pattern matching, if you wanted to. Assuming you construct tagged unions like so: Valid 123 Error "Error message" You could pattern match on the left side of an assignment like so: Valid foo = dosomething() use(foo) Which would extract the wrapped value into 'foo' if the union's tag was 'Valid', or aborted/panicked/did something else somewhat sane if the value didn't match.
- pacala 14y agoIf my return value is an Exception, I handle it in a catch block.