News for hackers. Stuff that matters.
Re:Comparing k-NN in Rust by pcwalton on Tuesday June 10, 2014 @12:19PM (#7873466)
From the perspective of a compiler writer, the most interesting thing about this code is that it contains no bounds checks while still being safe. Using the high-level iteration APIs like map/filter/etc. is not only good for readability, it's good for performance as well. C-style for loops require bounds checks to maintain safety, but there's no need for them with a properly designed iterator API.
Re:Comparing k-NN in Rust by andrewflnr on Tuesday June 10, 2014 @05:18PM (#7875378)
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.

Re:Comparing k-NN in Rust by dbaupp on Tuesday June 10, 2014 @07:02PM (#7875795)
The 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...

(Notably, since it's all in the types, you're guaranteed to not ignore any errors.)

Re:Comparing k-NN in Rust by ben0x539 on Tuesday June 10, 2014 @06:53PM (#7875756)
.unwrap() is checked, if it goes wrong, it will safely cause task failure and stack unwinding. There won't be any memory unsafety.
Re:Comparing k-NN in Rust by andrewflnr on Wednesday June 11, 2014 @02:52AM (#7876751)
You can't get corruption, but I don't consider a program that violently terminates on unexpected input to be "safe". Just semantics, I guess.
Re:Comparing k-NN in Rust by dbaupp on Wednesday June 11, 2014 @03:26AM (#7876826)
Yeah, saying 'safe' around Rust is generally interpreted as meaning memory safety.
Re:Comparing k-NN in Rust by mbrubeck on Tuesday June 10, 2014 @05:52PM (#7875545)
The `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."
Re:Comparing k-NN in Rust by tritri on Tuesday June 10, 2014 @04:34PM (#7875154)
That's actually very interesting, I've had to implement bounds checking in a C-style language, and it definitely was a lot of fun and required some thorough checks. What's taken into consideration when designing the iterator API? Could you please provide an example of using a properly designed iterator API?

Thanks!