3 ms·
Bob needs to sort an array of floats. Bob tries xs.sort() Bob gets an error message. Bob googles "how to sort an array of floats in Rust". Bob pastes in
by alextgordon 12y ago
Bob needs to sort an array of floats.
Bob tries xs.sort()
Bob gets an error message.
Bob googles "how to sort an array of floats in Rust".
Bob pastes in
xs.sort_by(|a, b| a.partial_cmp(b).unwrap_or(Less))
Bob continues on his merry way.
No safety has been added, no technical debt has been avoided. It's not any less "quick and loose".
The need to sort arrays of floats doesn't disappear simply because the Rust designers will it to. The code will still exist, but it will be longer and less maintainable. This is what I mean by punishment.
If anything, Rust has given you a false sense of security. The modules and other code you work with will still be handling NaNs incorrectly.
My preference, all considered would be a .sort() that pushes the NaNs to the front or back (but is slightly slower), and a .sort_unsafe() that assumes no NaNs but is faster.
- kibwen 12y agoI'm still reeling from how cynical and dismissive this comment is. The Rust developers don't like IEEE 754 any more than you do, but it doesn't change the fact that IEEE 754 is what hardware implements. I encourage you to take your complaints up with hardware vendors and the IEEE, as well as with with the popular programming culture of blindly pasting SO answers into your programs in frantic attempts to get them to compile at any cost. As for me, I very much appreciate that Rust is conscientious enough to throw up a red flag and force me to realize that this seemingly-simple task is actually quite complex, rather than implicitly imposing a leaky abstraction.
- Ygg2 12y agoWell, hopefully first answer will be stack overflow which will address this topic :P Rust community has been hard at work, answering a lot of Rust question. I don't think I've seen many unanswered so far. Well, when Bob found sort_by and a weird partial_cmp he should have paused there and look at docs if he understood nothing. In case of Python he is rightly to blame Python for silently doing stuff for him that he doesn't like. It's like a speed bump. If you go fast over a speed-bump, ignoring it, you suffer the consequences. It's different than a dark unlit road that just has a sign THIS WAY.