2 ms·
Functional languages make concurrency easier (particularly the statically typed ones, but also erlang thanks to its innate concurrency model) because they gener
by Jtsummers 10y ago
Functional languages make concurrency easier (particularly the statically typed ones, but also erlang thanks to its innate concurrency model) because they generally encourage low coupling between components of your system.
OO languages have not done this as a language feature (it's touted as a good thing, but is often ignored). It's too easy to call directly into another class, or to add a method to a particular class rather than via an interface. This means your system components know too much about each other and it's too easy to get around problems by reaching into one area and directly managing it.
OO languages or libraries implementing actor models allow you to design your system in a more decoupled fashion. But, of course, this leads to issues with performance.
That's to be expected. And there's a solution to this. Hide the implementation. I have a database server, I need it to be fast but an actor model implementation was too slow. Fine, I implement it in C on an exokernel with direct access to the hard drive and the ethernet interface and it's really freaking fast. But everyone else sees it as an actor. They don't need to know the implementation details. They just need to know how to talk to it. That that one component of your system wasn't implemented in a "pure" fashion is irrelevant. The rest of your system can't reach into it directly and become dependent on it (outside performance) in a way that makes your system fragile by becoming too tightly coupled.
EDIT: Also, concurrency != parallelism.
Concurrency is more an element of system design, less an element of system performance (though it lends itself to better performance). Parallelism is an implementation detail and all about the performance (how many tasks can we do at once).
Actors may or may not help with the latter. They certainly won't for scientific programmers, on their own, because they're likely too heavyweight in most implementations. Instead you want something like what OpenMP or MPI offer. Some functional languages allow you access to similar parallel computational models. But that, again, is separate from concurrency.