3 ms·
Does Clojure actually force you to use those abstractions though? Many languages provide concurrency primitives, but Rust will fail to compile if you try to use
by nicoburns 7y ago
Does Clojure actually force you to use those abstractions though? Many languages provide concurrency primitives, but Rust will fail to compile if you try to use non-concurrency safe objects from multiple threads.
- aratakareigen 7y agoRight. The main advantage of Rust is that its thread safety is opt-out (unsafe) rather than opt-in (remember to use the right data structures / locks).
- dgb23 7y agoIn short: it is inconvenient to use mutable state and unidiomatic to not use the STM. The long version is that you could use 'set!' with Vars. But this is very much an avoided practice. Another caveat is that Clojure is hosted (primarily JVM and JS), so any code you call via interop has the characteristics of the host target. But idiomatic Clojure uses at least Atoms or Refs and even those are discouraged for anything else than storing state, all the algorithmic (transformation, branching and so on) code follows the FP paradigm. A Rust analogy is the 'unsafe' escape hatch. You can use it but it would be unidiomatic, inconvenient and in most cases unnecessary.
- fnord123 7y ago>Does Clojure actually force you to use those abstractions though? tl;dr: no
- dgb23 7y agoThat comment is somewhat disingenuous. It is like saying that Rust is an unsafe language, because of 'unsafe' or the mere fact that you can just use stringly types for everything. Both using 'unsafe' and using String instead of an Enum would compile without runtime guarantees. But such code would stick out.
- int_19h 7y agoIs STM still idiomatic in Clojure? I had the impression that it is considered kinda legacy at this point.
- throwaway17_17 7y agoThis is sort of a question, but doesn’t Rust refuse to compile even when you use non-concurrency safe objects in a single thread? I think that is the case
- steveklabnik 7y agoIt is the case, yes.
- aratakareigen 7y agoRust types have markers (Send, Sync) that tell the compiler whether they can be moved across threads, and whether they can be simultaneously accessed across threads. These markers are irrelevant in a single-threaded scenario.
- steveklabnik 7y agoIt's not purely about those markers. Many people also believe that the only issue with aliasing is when threads come into play, but that's not the case. Rust also prevents mutable aliasing even in non-threaded cases for this reason.
- giovannibajo1 7y agoIs there any explanation of this? Specifically i would like to understand how a single mutable reference is required for correctness in a single thread scenario. I’ve googled everywhere but I can’t find a single source of information that completely explains this, possibly showing realistic source code and elaborating the way it could generate memory errors or be miscompiled in case of multiple mutable references.
- steveklabnik 7y agohttps://manishearth.github.io/blog/2015/05/17/the-problem-with-shared-mutability/ https://manishearth.github.io/blog/2015/05/17/the-problem-wi... is what I usually link folks to. The TL;DR is: iterator invalidation can happen even without threads.