3 ms·
Clojure with its focus on immutability and its purely functional data structures makes it much easier to write correct concurrent programs. It is clearly geare
by jnxx 6y ago
Clojure with its focus on immutability and its purely functional data structures makes it much easier to write correct concurrent programs.
It is clearly geared to servers, for example sequences are always lazy. This is not always the best thing but for servers, it seems in general better.
However, there is a subtle point about parallelism: One typically wants concurrency and parallelism for one of three objectives:
1. Concurrency in servers
2. Graphical user interfaces
3. exploiting many cores for complex parallel computations, like number crunching
It turns out that Clojure is great for the first application. It also works for the second one.
However it is not that great for the third area of interest. The reason is performance. For example, floating point numbers passed in function arguments are often boxed. Also, due to the JVM it is not possible to pass even small objects by value. These things put a lot of pressure on the garbage collector, even if the Clojure compiler partially tries to work around this.
And the result of that is that a single-threaded program which does things like massive number crunching written in Common Lisp will be faster than a parallel program written in Clojure.
But I still think that immutability in-the-large is the right way to go.