Erlang in simple terms: concurrency model with no shared memory source: https://www.youtube.com/watch?v=hht9s6nAAx8
Note
OOP is great for writing single threaded code, but the second you start to worry about multiple processes or multiple threads, you are in trouble, you have shared state, need to worry about locks or synchronising. The elixir bypasses it, the functional model with immutable data, means you don’t have to worry so much about shared state. With the amazing Erlang VM, we can run thousands of processes without breaking a sweat.
Source: https://www.youtube.com/watch?v=SOqQVoVai6s
Note
Declarative programming increases programmers productivity. Declarative programming gives you higher level of abstraction, which makes it easier to read and maintain. Declarative programs are much less code compared to traditional OOP such as CPP or Java (4 to 20 times lesser code). Defensive programming is not encouraged. In functional programming, if none of the clauses aren’t met, the program terminates. Allowing the program to terminal helps in keeping the program much simpler and smaller.
- Processes in Erlang don’t share state, it is immutable state. These are light weight processes.
- The code runs on an Erlang virtual machine, so the actual processes created by Erlang code is running detached from the underlying main OS and these processes are not exactly threads, but like processes but lighter.
- Every time we need a concurrent job or concurrency in our programs, we spawn a new processes.
- Example: In a chat application, every message processing would be done in a new process. After that code is finished, the process is terminated
- Its very easy to reason with code as it makes us think in terms of a single message.
- Processes do not share memory, they use message passing
- Supervisors can monitor processes and catch their exit state incase of bugs/terminations and decide to take actions(such as restarting). There can be sup-supervisors which can decide to terminate all the processes under it and the parent supervisor can catch the exit state.
- Error handling
- First at the sequential code level
- Then processes level
- Then supervisor level