Elixir
is fully functional, but it’s possible to create a OOP
-like API. For a good example check this library:
Since it’s more like than actually OOP
it probably does not have any compiler optimizations which are typical for OOP
languages. Of course there are also probably used other optimizations, but only for functional programming (Erlang
/vm optimizations).
In short Elixir
is based on Erlang
which used BEAM
(virtual machine). This allows to create your own processes (in BEAM
) even if you have started app once. Processes in BEAM
are much more lightweight than OS processes which means you one app can easily create thousands and even more processes (again in BEAM
VM). Each process can store its data which can be modified, but …
In OOP
languages you are working on exactly same data. In Elixir
you are working on data copies. So when you change data you are actually getting its modified copy rather than modified data itself (it matters in memory). What process is doing is basically replacing old data with its modified copy.
# old data
data = %{name: "example"}
# store old data
store_in_process(data)
change_data_in_process(name, "sample")
defp change_data_in_process(key, value) do
# old data
data = get_data_from_process()
# store modified copy
data |> Map.replace!(key, value) |> store_in_process()
end
Of course such code would not work - it’s just to visualize how its working inside.
For more information take a look at:
https://elixirschool.com/en
Especially in Advanced
group you have some info about concurrency.