4 ms·
The borrow checker also eliminates data races (and a variety of other bugs), something that most of the other languages on your list do not. While avoiding GC i
by pcwalton 11y ago
The borrow checker also eliminates data races (and a variety of other bugs), something that most of the other languages on your list do not. While avoiding GC is probably the most prominent reason for the borrow check's existence, it is not the only one. You shouldn't have to fight with it.
(Haskell in particular has a much more restrictive borrow checker than that of Rust: purity.)
- pjmlp 11y agoI think you overestimate how willing most developers are to fight with the borrow checker instead of using actor libraries or task libraries (TPL, TBB, PPL, Fork-Join, Akka) instead. So far the Rust tricks with unsafe for certain data structures (e.g. double linked lists/DAGs) seem like fighting with the borrow checker. Or the issues to be solved with upcoming 1.3 changes for pattern matching.
- pcwalton 11y ago> I think you overestimate how willing most developers are to fight with the borrow checker instead of using actor libraries or task libraries (TPL, TBB, PPL, Fork-Join, Akka) instead. That seems like a non-sequitur. What does the borrow checker have to do with actor libraries? Are you implying that these actor libraries give you the data race freedom guarantees that Rust's mutability rules give you? If so, that's trivially false. Those libraries guide you toward patterns that eliminate data races in simple cases if you follow them, but nothing enforces the rules. Moreover, being forced into actors or message passing for concurrency severely restricts the expressiveness of your program. Rust's approach lets you use shared memory if you like, or message passing if you like, or a combination of the two, with enforcement of the rules no matter which you pick. > So far the Rust tricks with unsafe for certain data structures (e.g. double linked lists/DAGs) seem like fighting with the borrow checker. Or the issues to be solved with upcoming 1.3 changes for pattern matching. Yes, they're tough. This is a downside of manual memory management (though one that can be improved in future iterations). But doubly linked lists/tree-like data structures are hard in Haskell too. "Tying the knot" is not exactly easy or intuitive.
- pjmlp 11y ago> Are you implying that these actor libraries give you the data race freedom guarantees that Rust's mutability rules give you? If so, that's trivially false. No they don't give the freedom, but they give them comfort for the average developers. I deal a lot with 9-5 enterprise developers that don't even know that HN and Reddit exist, or whatever languages exist out there besides what they use on the job. Yet they do write multi-threaded code with help of such libraries, happy that someone gives them training wheels. > But doubly linked lists/tree-like data structures are hard in Haskell too. True, but laziness helps. However Haskell is hardly a mainstream language.
- pcwalton 11y ago> Yet they do write multi-threaded code with help of such libraries, happy that someone gives them training wheels. And they create a lot of bugs in the process. Empirically, a message passing framework does not eliminate data races as a very common class of bug. > However Haskell is hardly a mainstream language. Well, you brought up Haskell earlier. I agree of course that both Rust and Haskell make it hard to write doubly-linked lists and trees, and that Haskell is not a common industry language.
- pjmlp 11y agoHaskell was just one of the languages on my list. I was basically referring to all languages with available compilers and better web frameworks than what Rust currently offers. And I did miss a few ones. As for data races elimination, I don't see people really moving away from those libraries, but I might be wrong.
- tinco 11y agoAs a Haskell programmer I feel this isn't exactly true. Haskell's garbage collector and referential transparency make immutability not really an issue. Impure code is simply of a different type, so it's easy to avoid. What makes dealing with the borrow check hard is that it triggers on code that intuitively is correct, it can be hard to envision why it's not. I feel Haskell does a better job at diverting you from incorrect code. That said, dealing the borrow checker is just a skill. You take out a few hours to learn to deal with it, and then you just can. As you said it's super powerful and definitely your ally, so saying its a downside of Rust is silliness.
- pcwalton 11y ago> What makes dealing with the borrow check hard is that it triggers on code that intuitively is correct, it can be hard to envision why it's not. Because it's more expressive than just forbidding mutability. You could program in Rust the same way you program in Haskell, by encapsulating mutability in functions with different types (&mut). Then the flow sensitivity and other issues would never bother you. Rust's flow-based control of mutability is strictly more expressive than the monad system of Haskell. If you don't like that expressivity, don't use it.
- Jweb_Guru 11y agoI disagree. I find immutably with GC much easier than mutability with the borrow checker for most tasks. The tradeoff is that you have to trust the compiler a lot to perform well, and that trust is not always warranted.
- pcwalton 11y agoYou can use immutability in Rust and the borrow checker will never bother you. The borrow checker allows you to take all the immutable references you want. What I think you are talking about is the lifetime system, which is not something that pjmlp mentioned.
- deleted 11y ago[deleted]