Erlang’s Shared Memory
Posted: May 14th, 2008 | Author: kevin | Filed under: Erlang | Comments OffYariv makes a good point about ets being Erlang’s sort of equivalent to shared memory. I agree totally.
What I like about Erlang is that ets, and hence shared memory, is totally optional. You can use ets when it’s suitable and ignore it otherwise. It gives you, the programmer, more control over the complexity of your code. The more I use Erlang the more I see the concepts of lightweight processes and message-passing simplifying and improving my code.
Other languages, like most of the OOP-y ones, come with shared memory baked into their models. From the first line you’re stuck in threading hell and you don’t even know it.
Of course, the state of blissful ignorance ends all to soon. It’s been my experience threads will get introduced at some point either explicitly — to speed up obviously parallel operations — or implicitly — such as when code which was never designed with a web application’s request/response model is integrated into a web application.
Then you’re stuck battling all kinds of threading issues. Race conditions, lock contention, etc, etc. I’ve been there many, many times and have the scars to prove it.
I much prefer to work in a language which helps me design my code in such a way as to avoid these problems from the start. 90% of the time I can solve my design problems by using Erlang’s processes and message passing. If I need to introduce shared memory into my code I can selectively include it in only the areas which truly require it without poisoning the rest of the code.