4 ms·
It's not really unique to Rust. Scala and Java both support this out of the box.
by vips7L 2y ago
It's not really unique to Rust. Scala and Java both support this out of the box.
- Filligree 2y agoYeah, but in Rust it’s far less likely to explode in your face.
- johnisgood 2y agoOr in Ada. Ada 202x[1] brings enhancements like the parallel block, making parallelism easier to express, somewhat similar to Rust's approach but still with Ada's emphasis on clarity and safety. [1] https://blog.adacore.com/ada-202x-support-in-gnat https://blog.adacore.com/ada-202x-support-in-gnat (2020) There may be more enhancements that I may not know about or remember, although I did mention Ada's constructs for safe concurrent code before.
- dwattttt 2y agoThe stronger guarantees/performance fall out of the stronger lifetime/ownership model, combined with errors around ambiguous/invalid lifetimes being a compiler error. In other languages those violations are things you have to run a race detector and actually evoke the condition to find, or you abandon fine grained/tracked ownership and use garbage collection.
- vips7L 2y agoNone of that matters with this code. There are no lifetimes here and in fact there is no ownership either. Everything is a primitive char. They’re always copied and no mutation occurs. It’s pure computation. You could write this code exactly the same way in those languages.
- dwattttt 2y agoTrue. You could write it in C or asm too, and it would be about as simple. But there's still a difference that if they weren't all primitive (and you can't always rely that they will be), you'll know it won't work straight away in Rust, whereas in the others you need to walk every data type involved to make sure ownership is clear (or rely on a garbage collector to save you).
- n_plus_1_acc 2y agoJava's HashMap for example is not thread-safe, but if you use it from multiple threads, you may or may not experience all kinds of issues.
- vips7L 2y agoAgain that only matters if there is mutation. Reads are perfectly safe to happen from any thread. This code is self contained. Rust isn’t a silver bullet here.