3 ms·
I feel like sometimes even `atom` gets over-used. When explaining to newbies, maybe we can say: > When you need Clojure STM, you usually don't, there is usuall
by capableweb 4y ago
I feel like sometimes even `atom` gets over-used. When explaining to newbies, maybe we can say:
> When you need Clojure STM, you usually don't, there is usually another way. But if you really, really do need it, default to using an atom unless you really know you need to use something else.
- robto 4y agoThere's a handy chart in "The Joy of Clojure" that I refer to whenever I'm trying to tackle concurrency problems: | | ref | agent | atom | var | | coordinated | x | | | | | asynchronous | | x | | | | retriable | x | | x | | | thread-local | | | | x | Turns out I have never needed coordinated, synchronous stuff. I have dabbled with agents, but just for an Advent of Code problem. I do like that 63% (!!) of clojure repos have no mutable references at all - that tracks very strongly with my experience. And that the average number of mutable references is less than 2! Immutability can carry you a long ways, and I love that I can trust that contract. On the other hand, it's nice that I can opt in to mutation really easily if I need it.