by symmetricsaurus · 4y ago · 0 comments
Not having data races is one of the key benefits of using Rust, “fearless concurrency” and all that. So by throwing away a key guarantee of Rust (no aliasing mutable references), it can become easier for learners to program in. It becomes a bit of an apples and oranges situation at that point.
1. Using a placeholder (let/var/val/auto/...) -- e.g. in modern C#/Java/C++/Kotlin -- and letting the compiler figure out the type, but keep the actual type known at compile time. This will give you compile time errors when using the wrong types, and keeps the variables of a fixed type.
2. Effectively making all types variant types that can hold any value and can change their type -- e.g. in JavaScript/Python/Ruby -- such that they are dynamically typed. This can lead to runtime errors.
For languages like C#, Java and the derivatives, they have the concept where all objects are instances of a common type. If you use this -- especially in collections -- you can also get runtime errors. As long as you stick to the generic versions of these, the compiler will enforce the type safety.
The statically typed languages have been making types optional where the compiler can deduce them to avoid redundancy and duplication. If there is an ambiguity, the compiler will omit a compiler error. This is the best of both worlds -- type safety without the noise of annotating types everywhere.
I think this research highlights a important strategy to make all software safer.
A quote from the discussion section:
> Encouraging adoption of safer languages by reducing stress.
In that sense, adding a gc to rust for single threaded programming, is almost useless : it's not helping that much and you're not learning.
When I have started with rust I was not writing stuff with Box/Rc/Arc... or even explicit lifetimes. Not saying that I was cloning everything but for simple stuff you can come long way with just moving and simple borrowing.
For an already experienced programmer, it's hard not to think about using multiple threads, even when just starting in the language. I know my few first Rust programs were using multithreaded constructs and I found that especially easy to do safely in Rust (when I started, there was already crossbeam and rayon, both making a lot of things easier).
Why not? I mean, maybe not your first ever programming language, but - why should you not get used to doling out work to all available threads to begin with?
If you don't or are unsure about that, then stick to simpler forms of programming or use type-hinted Python instead.
This would the recommendation I would make to anyone asking me that question !
Exactly. Lifetimes, borrowing, etc. are the complexity of thread safety. It's like saying that airplanes are easy to fly, if you replace the airplane with a car.
Having different levels of abstraction within the same language can be really useful.
But you don't want to overcomplicate the language to support that, especially if it makes operating at different levels more complicated.
In this case, it seems like an odd tradeoff to make. The less sophisticated user is exactly the same kind of user that is more likely to foot-gun themselves with a memory or thread-safety issue. The "right" answer is probably a thread-safe garbage collector, but that has its owns set of usability and implementation tradeoffs.
I think it's often pretty easy to not footgun yourself with thread or memory issues, because these issues simply don't exist in wide swaths of application.
And for the cases where having managed pointers are better, Rc/Arc are often (not always) good enough.
(There are limits, though: if you map the same physical addresses to different virtual addresses, Rust can't help you. However, that is independent of threads/processes, because you can also do that in single-threaded programs.)
Hence why I try to make a point that comes with a footnote.
Rust is after all supposed to target all kinds of system programming scenarios.
Frankly, you're being a bit disingenious. Nobody claimed that Rust can or will solve all conceivable concurrency problems. "Fearless concurrency" is generally understood to mean "...within a single program", not "...across different processes/machines/networks". By the time you understand what interprocess shared memory is, you're well able to correctly interpret Rust's "fearless concurrency" slogan.
Are you talking about databases, services or IO and such?
Even Python has it: https://docs.python.org/3/library/multiprocessing.shared_mem...
It's not "even". Python specifically has it because it has no real threading.
What data races between processes, other than Disk/IO, databases, or external services, can a Rust program have?
I explicitely exclude the whole category of external services, since that is "by design" really. And the whole reason for ACID, global mutexes, transactions and CRDTs.
Locales.
Quite a few other POSIX bits, really.
I'm not sure what data race is possible across processes with locales, that's too vague of a claim to make.
Of couse it will require nightly since auto traits are not stable.