3 ms·
In the context of this article and discussion, panics via unwrap (or better, expect) is a fine answer, and I'm not sure why you think it is hypocritical to sugg
by jjnoakes 9y ago
In the context of this article and discussion, panics via unwrap (or better, expect) is a fine answer, and I'm not sure why you think it is hypocritical to suggest it, especially to Rust newcomers who are looking to write script-like programs.
Panics mostly match the verbosity, ergonomics, and functionality of the analogous python script.
Now I agree that a caveat should follow advice like using unwrap and expect, perhaps a small blurb about how they should eschewed for better error handling when you want to catch the errors and make decisions because of them (especially when writing libraries) but that's quite a bit short of hypocritical to me.
- shadowmint 9y ago> a caveat should follow advice like using unwrap and expect, perhaps a small blurb about how they should eschewed for better error handling when you want to catch the errors and make decisions because of them. That is literally the definition of hypocrisy; the behavior of people who do things that they tell other people not to do. "When you do this, do it like this, but properly with error handling." :P Anyhow, as I said its my oppinion that unwrap() is lazy, and `?`, `expect` and `assert!` cover the same functionality in more explicit and meaningful way. You're welcome to your own opinion.
- jjnoakes 9y ago> That is literally the definition of hypocrisy; the behavior of people who do things that they tell other people not to do Except I'm not saying that at all. I said it's fine to use unwrap() or expect() if you want script-like default behavior (a developer-centric error message and a quick exit with a bad return code) and if you want something more than that, then use something better than unwrap() or expect(). There's no hypocrisy here. I think anyone should follow that advice. Me, you, a newb to Rust, a Rust veteran, anyone. Same advice.