Hacker News new | past | comments | ask | show | jobs | submit login

I find it surprising that so many people are arguing about the benefits and drawbacks of `?`, when in my experience the handling of Result and Option haven't been an issue in practice on the consuming side (`?`, `.unwrap()`, `.map()`, `.ok()`, if let, match, let chains, let else, etc. help a lot), but where all the pain comes from is having to declare the appropriate error type itself. Libraries like `anyhow` takes some of the pain away, but declaring an appropriate struct or particularly an enum in the right places, and the boilerplate for all the type conversions (From/Into impls) are where, during development, I have frustration. What I do then is either use Result<T, ()> or a single `struct Error(String);`, and go back once I have all the scaffolding in place and pry the implicit error tree back into the type system. Anonymous enums like typescript (`A | B | C`) could presumably help here.



I've run into similar issues and found that the `thiserror` crate (https://crates.io/crates/thiserror) combined w/ anyhow makes a lot of that pain go away


For those reading this that aren't super familiar, common Rust advice is "use thiserror for libraries and anyhow for applications," as they make slightly different tradeoffs and so are useful, especially together.


`anyhow` + `?` make writing an application as smooth as butter. You won't miss exceptions.

Don't use `anyhow` for libraries, though. You want to provide your consumers the ability to `match`.


here we go again!


I would add `snafu`(https://crates.io/crates/snafu) here as a good alternative to thiserror+anyhow.


All these workarounds for easier Result handling truly make me wonder whether Rust will eventually evolve exceptions as a feature - of-course without explicitly terming them so.


The community would revolt. Not going to happen.

Proposals to make the existing syntax and semantics even look more like exceptions were met with lots of hostility.


Revolt how? Go back to C++ or whatever language/s they were using?


I don't know exactly, but it's never pretty when a project's leadership makes an unpopular decision. Lots of complaining, for sure.


Rust already has exceptions, they just call them panic and offer exceedingly poor language support for them.

Some people simply live in denial, believing untruths that confirm their worldview.

This is the same situation as with Go and generics. The maintainers were in denial for a very long time, before finally admitting what was obvious to some of us long before [1]

[1] https://news.ycombinator.com/item?id=8626978


The implementation, outcome, use-case, and characteristics of panics are all very different from exceptions. The only marked similarity between the two is that they both interrupt program execution (and in different ways). But I feel as if you already knew that.


Panics support stack traces, unwind the stack, releases the memory, and can either be recovered in some situations, or prints an error message. Sounds like Python exceptions.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: