Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

meh.

I feel like any time someone mentions the word 'safe' regardless of context, the rust safety pedants roll out of the woodwork to dispute to dispute any minute detail of what's been said, regardless of if its relevant to the discussion at hand. I shouldn't have put 'safe' in the comment at all, what a waste of a thread.

My point had nothing to do with safety; it was purely that having given advice being to write good code that doesn't panic, and then having code that shamelessly panics in all your examples is hypocritical.

`?` is a better choice in basically every case; I'm glad to see the documentation will be moving eventually towards using that.



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.


> 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.


> 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.




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

Search: