| ▲ | Chai-T-Rex 3 hours ago |
| That's not really a memory safety bug, due to the fact that it panics rather than doing something unsafe. The `variable[i]` notation is intended to function like in other languages, where it returns an unwrapped value. It would be ugly, noisy, unergonomic, and annoying to have to properly handle `Some` (like in `variable[i].unwrap()`) every single time you ever used it. Imagine doing `c[i].unwrap()[j].unwrap() += a[i].unwrap()[k].unwrap() * b[k].unwrap()[j].unwrap();`. If you really want the result to be wrapped in `Some`, you can use `variable.get(i)`. |
|
| ▲ | cube00 3 hours ago | parent | next [-] |
| > That's not really a memory safety bug, due to the fact that it panics rather than doing something unsafe. The ? operator can be nicer to read then all those .unwraps() as an alternative and doesn't panic. I guess the concern with panics is you're not forced to think about how you want to handle them like you do when you get a `Result` or `Option` returned. As a result it could be used as a DDOS against your app if it's network accessible. |
| |
| ▲ | aslilac 2 hours ago | parent | next [-] | | gotta remember tho that ? didn’t exist in 1.0, and now we can’t break existing code | | |
| ▲ | cowlevel 38 minutes ago | parent [-] | | Is that Rust's guarantee? I know that Go avoids breaking changes but I thought they were normal in Rust. |
| |
| ▲ | adwn 2 hours ago | parent | prev [-] | | Applying the ? operator to an Option<_> doesn't work inside a function returning io::Result<_>, for example, and turning the None from an out-of-bounds vector access into some io::Result::Err usually wouldn't make sense. I would go so far as to say that an out-of-bounds index is always a logic error (to be handled by panicking), not an input error (to be handled with Result). And if the out-of-bounds access was caused by invalid input, then logic error consists of not checking the input before indexing. | | |
| ▲ | ablob 25 minutes ago | parent [-] | | The former issue arises from post-hoc thinking. Of course it's hard to retrofit into the language, but I see no reason why there shouldn't be facilities for the ? operator to turn a None into an appropriate error type. The latter is a subjective matter. There are reasons to never want a panic (hello there, Linux kernel) and reasons to do more sophisticated stuff (core dump, cleanup or notifications) before crashing. And maybe one thread shouldn't lead to process death. I think most of these decisions should be kept to the user's discretion. |
|
|
|
| ▲ | rendaw 2 hours ago | parent | prev [-] |
| GP didn't say it was a memory safety bug. |