4 ms·
What about all those calls to unwrap? Don't those sweep some of the bounds checking under the rug? It's okay in a proof of concept like this, but I wouldn't be
by andrewflnr 12y ago
What about all those calls to unwrap? Don't those sweep some of the bounds checking under the rug? It's okay in a proof of concept like this, but I wouldn't be comfortable running that code "for real".
Edit: to be more clear, I wouldn't expect it to have an impact on performance, but I'm not convinced this is a good example of expressiveness and safety in the same package.
- mbrubeck 12y agoThe `unwrap` calls are all in the input parsing code (`slurf_file` fails if input is invalid), except for one on the result of `min_by` (`classify` fails if you pass it an empty array). I wouldn't say any of these "sweep bounds checking under the rug."
- ben0x539 12y ago.unwrap() is checked, if it goes wrong, it will safely cause task failure and stack unwinding. There won't be any memory unsafety.
- andrewflnr 12y agoYou can't get corruption, but I don't consider a program that violently terminates on unexpected input to be "safe". Just semantics, I guess.
- dbaupp 12y agoYeah, saying 'safe' around Rust is generally interpreted as meaning memory safety.
- dbaupp 12y agoThe unwraps are not memory unsafe, unlike avoiding bounds checks. In any case, rewriting to avoid them isn't so hard: http://huonw.github.io/2014/06/11/error-handling-in-rust-knn-case-study.html http://huonw.github.io/2014/06/11/error-handling-in-rust-knn... (Notably, since it's all in the types, you're guaranteed to not ignore any errors.)