this post was submitted on 23 Jan 2024
364 points (96.7% liked)
Fediverse
28246 readers
209 users here now
A community to talk about the Fediverse and all it's related services using ActivityPub (Mastodon, Lemmy, KBin, etc).
If you wanted to get help with moderating your own community then head over to [email protected]!
Rules
- Posts must be on topic.
- Be respectful of others.
- Cite the sources used for graphs and other statistics.
- Follow the general Lemmy.world rules.
Learn more at these websites: Join The Fediverse Wiki, Fediverse.info, Wikipedia Page, The Federation Info (Stats), FediDB (Stats), Sub Rehab (Reddit Migration), Search Lemmy
founded 1 year ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
view the rest of the comments
Yeah I suppose ignoring unchecked exceptions, it's pretty similar situation, although the guarantees are a bit stronger in Rust IMO as the fallibility is always in the function signature.
Ergonomically I personally like Result more than exceptions. You can work with it like with any other enum including things like
result.ok()
which gives you Option. (similar to javaOptional
I think) There is some syntactic sugar like the?
operator, that will just let you bubble the error up the stack (assuming the return type of the function is also Result) - ie:maybe_do_something()?
. But it really is just Enum, so you can do Enum-y things with it:In that sense it's very similar to java's Optional if it could also carry the Exception value and if it was mandatory for any fallible function.
Also (this is besides the point) Result in Rust is just compile-time "zero cost" abstraction. It does not actually compile to any code in the binary. I'm not familiar with Java, but I think at least the unchecked exceptions introduce runtime cost?