by Scorponok · 14y ago · 0 comments
(1) In C++ you may get hard crashes, so to get reliability you need to use high-overhead OS processes. Erlang allows you to hundreds of thousands (yes, really) of processes because they are really lightweight (76 words + heap/stack). Also, copying within the same address space has much lower overhead (no system call/context switch) and serialisation is much simpler.
(2) Because of immutable data you can do have nice fault tolerance as follows. Imagine you have a request handler function that takes a state and a request. However, the request is malformed or triggers a bug in the handler. In a language that doesn't enforce immutability you have to restart the handler process because the state may be in an inconsistent form. In Erlang you would just discard the request (or send an error message) and handle the next request with the unmodified state.
(3) Pattern matching makes receiving a message very convenient.
I probably forgot a few things, but this gives you an idea.
It might be possible to achieve that isolation if you stick to strict coding practices, but the point where it's going to fail is when you import another library, written by someone else.
Because C++, Java and many other languages (including F#, Scala and others which have message passing libraries) do not have the enforced isolation of state, nor the ability to add notation to indicate that some piece of code is free of side effects (including all of it's dependencies), you're always going to have the risk of breakage when importing a library. The only way you can be sure that a library is actor-safe is to read it's source code - and if the source code is not available, then you're out of luck.
Java and C++ could have the potential to do actors correctly by adding the notation for side-effect-free code, using custom annotations/attributes on all functions which are actor-safe, and using some compiler extension or static analysis tools to prove correctness. I'm not aware of anything that does this for the mentioned languages though.
On the other hand, if you implement message passing in any purely functional programming language, your actors are automatically safe for free.
Not sure why this is so tough for people to understand. You usually don't need a whole new language to use a paradigm.
I'll say it again: the benefits of the concurrency model described in the original article can probably be achieved in peoples' existing/preferred dev env. It's easier and faster to look into that then to throw what you have under the bus for erlang.
In this case, your thinking appears to be, "I can accomplish the same thing in C++, so why use Erlang?" My point is that an assembly programmer might just as well say, "I can accomplish the same thing in assembly, so why use C++?" The answer is that it's a lot easier and more natural to write OO code in C++ than it is to use, say, assembler macros. The fact that something is possible is less interesting than how simple and well-supported it is.
Again, I'm not saying your choice is necessarily wrong. For your use case, it might have been right. The benefits of using a language with pervasive and highly developed support for the paradigm might not outweigh the benefits of using C++ for you. But that reflects more on your personal circumstances than on the benefits of Erlang in general.
No, they can't. This has been well explained elsewhere. You'd have to rework the language/dev environment down to at least the C level if not assembly.
>It's easier and faster to look into that then to throw what you have under the bus for erlang.
No, it is slower and harder.
People think Erlang is difficult simply because the syntax is weird. Spend a couple weeks learning it and you'll be up to speed.
I think people are scared off by the syntax and so are trying to rationalize that they don't really need erlang.
It is possible to replicate erlang elsewhere, but you'd have to replicate erlang. You can't just add a library to ruby and get it.
edit: </internet sarcasm> ducks
I don't believe it is possible to do real concurrency on the JVM, without rewriting key parts of the JVM.
Because rewriting or shimming the 10MM lines of code in the libraries one depends on outweighs this one particular benefit of erlang.
> I don't believe it is possible to do real concurrency on the JVM, without rewriting key parts of the JVM
Define "real concurrency".
Multi-threading is doable in any number of languages, but the problems inherent with it are why people move to concurrency.
Concurrency needs to be supported in the language itself.
You'd spend 20 years recreating this in C++ vs 2 weeks learning erlang.