|
|
|
|
|
by freedomben
2107 days ago
|
|
I'm in the same place as you. I love using Elixir, but like you it doesn't feel very general purpose to me. I mostly just write Phoenix apps with it though. I went through Dave Thomas' book and it did feel like a mostly general purpose language when going through that, but of course those examples were chosen intentionally. It makes me think I just need to try more often. I'm so productive and fast with Ruby however that I always reach for that for scripts. I really need to buckle down and make myself write a non-trivial CLI tool in Elixir. Part of what I suspect might make it feel less general purpose is that unless you spend time really learning the internals then it seems somewhat mysterious and constraining. The immutability for example (which most of the time I love) made it a nightmare when I was trying to process and transform deeply nested JSON. I tried a few times in Elixir and just bailed to Ruby where I could directly mutate stuff 5 levels down with ease and efficiency. The code seemed way more straight forward and readable. How do people deal with things like deeply nested JSON in Elixir? Is there a way to make use of actors to avoid some of the pain points? |
|
Have you gotten to play with the `put_in/2` [0] and `update_in/2` [1] macros? They're designed to manipulate deeply nested structures like JSON
As a side note, a common misconception is that updating a large data structure on the BEAM is inefficient because values are immutable, so you have to copy the whole structure to make a tiny change. This is untrue, as Elixir (and Erlang) "maps" are implemented as HAMTs[2], which support very memory efficient updates by "sharing" the unchanged parts between the the old and updated maps.[0] https://hexdocs.pm/elixir/master/Kernel.html#put_in/2
[1] https://hexdocs.pm/elixir/master/Kernel.html#update_in/2
[2] https://en.wikipedia.org/wiki/Hash_array_mapped_trie