184 karma · joined September 19, 2017
match a.cmp(&b) {
Ordering::Equal => 0,
Ordering::Greater => 1,
Ordering::Less => -1
}
It's easy to see what the possible outputs are and what is produced in each case. The compiler even checks it to make sure you didn't forget any situations.The clarity comes at the cost of some verbosity, but there's only 4 lines of functional code (not counting the closing brace) here compared to the article's 10. You'd get around the same number if you added line breaks to make the ternary example more readable.
It's essentially the reverse case of telling Windows users to "just use Wine" - the emulation isn't perfect and some programs won't work well or at all. In a sense, WSL is worse than Wine in this regard since there's usually a Linux-native alternative if something doesn't work in Wine. If something doesn't work in WSL, you don't have a lot of options.
fn leak() {
// Create a 1KiB heap-allocated vector
let b = Box::new(vec![0u8; 1024]);
// Turn it into a raw pointer
let p = Box::into_raw(b);
// Then leak the pointer
}
Obviously that's kind of blatant, but there are more subtle ways to leak memory. Memory leaks aren't considered unsafe, so even though they're undesirable the compiler doesn't guarantee you won't have any.Reference cycles when using Rc<T> are a big one, but generally it's pretty hard to cause leaks by accident. I've only run into one instance of leaking memory outside of unsafe code, and that was caused by a library issue.
The usual answer I've heard here is to use an SPA, but those have problems of their own. They chew up huge amounts of memory if you use tabs, their UX is worse than if you'd just built normal webpages, you have to deal with making it indexable, and so on.
Honestly, I'd be ecstatic if most pages loaded in two or three network round-trips. A cold request takes maybe 100ms when I'm on a cell connection, but JS-heavy pages I've seen tend to have load times measured in seconds.
"Good enough" might stop people switching away from the platform, but it's not enough to bring back those who've already left. If Microsoft wants to bring people back to Windows as opposed to just stopping the bleeding, they'll have to deliver an experience that's actually superior to the other platforms. Given the current state of Windows 10, I don't think they'll have an easy time pulling that off.
There's a chance of data loss, of course, but the write performance is so good that it's a perfect fit for workloads like analytics or logging.
foo.into_iter().map(|x| x+1)
.filter(|y| y > 2)
My working theory is that it's related to situations where there's multiple statements on the same source line (or inside a block inside a lambda).I haven't yet experienced a web-based application that I actually enjoyed using. The closest anything ever gets is to make me wish it was a native application so I didn't have to deal with all the web nonsense in order to use it.
Unless that becomes a possibility, I'm happy that we can cut down on the randomness of the genetic lottery.