To clarify, my statement was aimed at Quora as a whole, not at any particular individuals on Quora. That said, I do partially retract it: upon doing some research, turns out Quora does do some answer quality assurance (as it were). They're just not nearly up-front about it as the Stack Exchange sites (and many forums) are, which makes it harder to build trust in the responses there.
Cubbi wrote: |
---|
As far as I've seen, the "common idiom" in Rust is to panic, and maybe provide a non-panicking alternative that nobody uses, e.g. thread::spawn vs thread::Builder::spawn. |
That has not been my experience. The "common idomatic" approach I was referring to was to use Result (I'll get to my thoughts on the standard library not always using it below). That general practice isn't limited to Rust, but is fairly common among all functional programming languages that provide a single standard way of doing something similar. And most well-designed libraries that I've used have been religious about it.
That said, there absolutely is a lot of panic abuse in Rust, and when I said earlier that there were some things about the language that I hate, that's definitely one of them. It's like assert abuse all over again.
Cubbi wrote: |
---|
This kind of approach is exactly why in C++ world, most open-source libraries are off-limits when writing software that needs to survive OOM or other resource-constrained conditions. Once something transitively uses glib or webkit, you're dead (their allocation functions terminate on OOM, providing alternative APIs that nobody uses). But standard library and some other high-quality libraries, so far, have been acceptable. |
So there are four saving graces to Rust's panics, which is why I call Box::new()'s behavior questionable instead of downright broken:
* Panics are thread local.
* Panics unwind the stack. Destructors still get called in reverse order on panic.
* For safety-critical applications, Rust's standard library allows you to either react to panics (with set_hook) or catch them entirely (with catch_panic or catch_unwind).
The fourth one takes explanation. Panics can be changed to not unwind and instead abort, with all the explode-the-world things that entails. Doing so requires explicitly opting in to a specific feature of the standard library, which is incompatible with a complementary feature that guarantees that panics unwind. In short, we get compile-time checking for if a library a safety-critical application transitively uses would abort on panic.
AFAIK there have been some slow efforts to add a way to more elegantly recover from OOM problems (specifically, as opposed to any other panics) without changing the API of Box::new(), but none of them have landed yet. That's what I meant when I said that OOM wasn't recoverable, and I'm sorry for being misleading.
Cubbi wrote: |
---|
OOM handling is not about being memory-intensive, it's about reliability (servers that don't die from large/hacked requests), transactional integrity (every sane database e.g. postgres), preserving unsaved user data, and many other aspects of software engineering.
|
Maybe I wasn't clear on what I meant. I didn't mean to imply that memory-intensive programs are the only ones likely to face OOM, only that the class of programs most likely to run into OOM issues are also the ones most likely to NOT use the default Rust facilities for heap allocation. Apologies.
zapshe wrote: |
---|
I personally can't see where Rust would have a specific advantage over C++ if you're dealing with a programmer who knows what they're doing. |
Except programmers cannot be trusted to always know what they're doing at all times. Even excellent programmers have bad days. That's why we do code reviews. That's why we do automated code testing, and coverage checks to make sure those tests are as complete as possible.
But Rust is not a single-issue language. It tries hard to be pleasant to use for people who've gotten a taste of what functional programming can offer. Generic traits are more or less type classes. Enums are full-blown algebraic data types with pattern matching and de-structuring. Most containers in Rust are at least somewhat monadic. Most expressions in C++ that don't have a value do in Rust. In short, once you get used to its syntactic differences and having to express your ownership model in code, it can be very pleasant to use. And yes, that's a valid reason for wanting to use a language. Else nobody would use Ruby.
-Albatross