|
|
|
|
|
by isbjorn16
2028 days ago
|
|
I don't know that I agree that you're doing an apples to apples comparison though. There's nothing to stop you from doing: let x = doRiskyThing();
match x {
Ok(x) => x.doThing(),
Err(e) => ...
}
x.get().doThing();
That would be more comparable to the try catch from above, and a comparable try catch that actually is semantically approximate would be: try {
MyType x = doRiskyThing();
x.doThing();
} catch(CheckedException e) { ... }
Putting these two together, it makes the Result type seem worse than a try catch, right? But that isn't fair to result, because I'm using it like a jackass.In other words, you can be a jackass using either of them, but you can also use them correctly, and when you use them correctly I don't see how they're any different. I also don't feel like the likelihood of using a Result correctly (edit: originally this said _incorrectly_) is substantially higher than a try/catch, but it probably boils down to developer experience and comfort with a particular varietal and not the capabilities inherent in either. Probably. And if not, I'm looking forward to being shown why! :) |
|