Earlier quoted context omitted.
What do you find more difficult? The achieving tasks in it or the getting paid to do so part?
There’s definitely a bit of a learning curve if you’ve never written in a language where everything is immutable. Certain problems have to be approached in a fundamentally different way if you can’t mutate state. Fortunately there’s Agent/OTP, but again, pretty different than other (or popular with beginners - js/python/java) languages.
Unpacking Elixir: Concurrency
31–40 of 138 posts
Re: Unpacking Elixir: Concurrency
#32Earlier quoted context omitted.
all the C family all the JVM languages all the .Net languages Rust Ruby Python etc.
Thanks. What's the Ruby example? It's the one I'm most familiar in.
irb(main):002:0> ["GFG", "GFG", "GFG", "GFG"].class
=> Array
irb(main):003:0> {1 => "CFG", 2 => "CFG"}.class
=> Hash
irb(main):006:0> {1 => "CFG", 2 => "CFG"}.keys.class
=> Array
irb(main):007:0> {1 => "CFG", 2 => "CFG"}.values
=> ["CFG", "CFG"]
irb(main):008:0> {1 => "CFG", 2 => "CFG"}.values.class
=> ArrayRe: Unpacking Elixir: Concurrency
#33Earlier quoted context omitted.
Vs which other languages - do you have examples of better patterns?
all the C family all the JVM languages all the .Net languages Rust Ruby Python etc.
Re: Unpacking Elixir: Concurrency
#34The deal-breaker for me with Elixir has always been the lack of real Elixir vectors rather than the crappy Erlang array library. Yes, I know you can use a Map with numeric keys but that's not the same.
Re: Unpacking Elixir: Concurrency
#35Earlier quoted context omitted.
What would be the difference between a "real vector" and a Map with numeric keys?
Maps are hashtables, Vectors are a contiguous area of memory where each element can be access by index referring to a specific address in that memory. Vectors are usually also homogeneous about the data they hold, because each element should occupy the same fixed amount of memory, such as i*item_size gievs you back the offset of the element i in memory. Anyway, in Elixir you can use the Erlang's :array module
Re: Unpacking Elixir: Concurrency
#36Unlike javascript, elixir makes you write synchronous code, e.g. def process_items(items) do items |> Task.async_stream(&Processor.process/1, max_concurrency: 2, timeout: 7000, on_timeout: :kill_task) |> Enum.to_list() end Semantics of regular and concurrent code is the same
I'm not saying I'm happy about this or that the meaning has "really" changed; I'm just saying from experience you don't really want to phrase it this way because you only reach those who already know.
Re: Unpacking Elixir: Concurrency
#37I think a few code example would have been nice. The thing I like about concurrency in Elixir is that it's there if you need it but it's mostly not mandatory in your code, compared to Javascript where its kind of imposed on you even when it's an hindrance. I remember one trick I used to do with LiveView on click events etc was to put all async (or "asyncable") code in a spawn function, which would speed up the return…
Yes exactly! This is super important for people new to elixir. The vast majority of the time, you don't even need to know that there is even any concurrency. You can write entire sophisticated Phoenix apps and never need it. But when you do eventually need it, it's there and it's wonderful, once you grok the pattern.
--
[0] By thread I mean the general concept, not specifically OS threads. In this case it includes the fine-grained processes offered by the BEAM VM that underpins Elixir and Erlang.
[1] https://journal.stuffwithstuff.com/2015/02/01/what-color-is-...
Re: Unpacking Elixir: Concurrency
#38Unlike javascript, elixir makes you write synchronous code, e.g. def process_items(items) do items |> Task.async_stream(&Processor.process/1, max_concurrency: 2, timeout: 7000, on_timeout: :kill_task) |> Enum.to_list() end Semantics of regular and concurrent code is the same
This. I don't want to be in an event loop by default.
Re: Unpacking Elixir: Concurrency
#39Concurrency in Erlang sort of frustrates me...not because it's bad, but because when I use it I start getting pissed at how annoying concurrency is in nearly every other language. So much of distributed systems tooling in 2023 is basically just there to port over Erlang constructs to more mainstream languages.
Obviously you can get a working distributed system by gluing together caches and queues and busses and RPC, but Erlang gives you all that out of the box, and it all works.
Re: Unpacking Elixir: Concurrency
#40Earlier quoted context omitted.
all the C family all the JVM languages all the .Net languages Rust Ruby Python etc.
Python lists are generally not contiguously allocated memory (I think it might be if you are storing integers less than 255), don't be fooled. That's why you need numpy.
https://docs.python.org/3/library/array.html
>>> a = array('B', [1, 2, 3, 4, 5])
>>> str(a.buffer_info()[1] * a.itemsize) + " bytes at address #" + str(a.buffer_info()[0])
'5 bytes at address #4379640336'
>>> b = array('l', [1, 2, 3, 4, 5])
>>> str(b.buffer_info()[1] * b.itemsize) + " bytes at address #" + str(b.buffer_info()[0])
'40 bytes at address #4380812752'