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

What OP meant is that proponents of Rust are often a bit out of touch with reality: Go to github and find a random Rust repo which doesn't use unwrap excessively. And is thus full of serious bugs, according to your wording.


> Go to github and find one Rust repo which doesn't use unwrap excessively.

Consider serde-json, a widely used library to serialise and deserialise json. You asked me to find “one Rust repo”. Ok here it is - https://github.com/serde-rs/json/search?q=unwrap&type=. Of the 22 uses of unwrap, nearly all are in test code or in comments. Of the remaining 3 or 4, they seem safe to me. But maybe they’re not. Could you think of some json input that could trigger a panic from one of those unwraps?

I’ll put my money where my mouth is. I’ll donate $100 to a charity of your choice if you can find that.

But if you can’t, at least have the honesty to admit that you misspoke when you said not even a single repo without “excessive” use of unwraps exists.


Not every use of unwrap is a bug. For example a regex library returns Result on regex construction because the passed regex could be invalid. But if you construct the regex yourself, from a hard coded string, you know it is correct. Then you just use unwrap and it is ok.


People don't write bugs on purpose. That hardcoded string that you know is correct is sometimes not actually correct.


And crashing early is often the best solution in that case.




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

Search: