4 ms·
You can do it non-properly in Rust as well, e.g. using unwraps, etc. but even then it's still way better than an UB-ridden component of a C++ codebase.
by est31 6y ago
You can do it non-properly in Rust as well, e.g. using unwraps, etc. but even then it's still way better than an UB-ridden component of a C++ codebase.
- sinistersnare 6y agoUsing `unwrap` is not something that can come back to bite you in a long term (other than API design wise). Replacing it is dead easy, as the compiler helps you. Also, you can replace it with a call to `expect` to give a relevant message too.
- est31 6y agoThat's why I said it's way better. It's usage is still not considered good practice for most scenarios.
- rmdashrfstar 6y agoThose .unwrap() and .clone() calls make the points for optimization or improvement very obvious.
- atoav 6y agoSure you can create these situations in Rust as well, but it makes that choice very obvious. So instead of being like: Damn, there was a case that I didn't consider at all you usually are like That case I decided against handling before must be handled now. Of course you could still ignore it then, but the language made make this choice at every point consciously so it is totally your fault if it bites you later. I e.g. tend to comment on unwraps why they cannot panic, and if they could (because I wanted to follow another strain of thought first, I use except and a message or writw a TODO comment.