sodapopcan
What is the etymology of `GenServer.cast`
I want to be clear:
I am not asking what GenServer.cast/2 or handle_cast/2 does… I already understand this!
I’m purely interested in the choice of words when naming this function (along with its callback, handle_cast).
I do understand the concept of casting in programming languages. You convert from one type to another. Ecto.Changeset.cast also makes sense to me—It’s casting an unknown databag into a known one.
However, cast when referring to “I’m sending out a message yet don’t want a response and don’t even care if it was received”… what is this in reference to? Like, casting a spell? I can maybe sort of relate it to the standard programming term, though it’s more like “casting into an unknown”. That would actually be a good explanation as far as I’m concerned, but what was the actual intent behind the name?
Again, I’m purely interested in the etymology here—this is not a technical question. Whether I should or not, I get very hung on and interested in language. For example, why does the Hidden Fortress tile in Roll for the Galaxy yield just one warrior?—I excepted more from discovering an entire hidden fortress!!
Thank you
Most Liked
rvirding
I honestly wouldn’t read too much into the actual call names. They needed/wanted to label two different interfaces, the completely synchronous and well-checked and the asynchronous unchecked ones.
I am guessing here as I wasn’t on the otp team (I don’t do this high-level stuff but prefer the basics
).
So the basic erlang send is asynchronous and without any guarantees at all: the receiver may or may not be there and the message may or may not arrive. It really is a “send and pray”. There is in fact only guarantee and that is if you send 2 messages and both arrive they will arrive in the same order as you sent them. The gen_server/gen_statem:cast models this exactly, in fact if you look in the code it ends up just doing a raw send. So what do you call this? You could call this send as well but then people could get mixed up between it and underlying message sending. Also some OO system you send for the synchronous object call.
The name call is easier to understand. It has all the guarantees you can get: the receiver is there and alive, you will get a reply within your specified timeout and you will know if the receiver dies before it can reply. This is sort of close to remote function calls so calling it call is pretty good.
In the older now deprecated gen_fsm the calls were called send_event and sync_send_event.
It is interesting to look at the code for the synchronous gen_server:call. Check out the do_call function in the gen.erl module. It shows how easy it actually is to get this reliability. It shows how right we got the primitives ![]()
These are just my thoughts.
ryanwinchester
How I see it:
To cast something, is to throw it (“let him who is without sin cast the first stone”). So you cast a message, you don’t expect a response. You’re just tossing it over like, “Here, catch this.”
To call, like calling a person, (“Hello, Joe”), you expect a response.
Definition of cast
(Entry 1 of 2)
transitive verb
1a : to cause to move or send forth by throwing
Dusty
Although cast means “to throw,” the traditional usage of cast implies specifically that you are throwing the item with the mentality that the item will never return. This is why people don’t cast baseballs, but they do cast things into the sea, and they do cast off their chains. This is why we have “outcasts,” “castaways,” and other individuals who are presumably gone forever. It’s an excellent choice for the function in question, I think.
Last Post!
brettp
As both an Elixir developer and language nerd I can’t resist this.
For me, handle_cast always brought to mind broadcast. The throw without expecting anything back meaning makes sense too. (I guess calling it throw would be confusing because that is used in a lot of languages for exceptions.)
From the Oxford, that sense of cast is this one:
1 [usually with adverbial of direction] mainly literary throw (something) forcefully in a specified direction: he cast the book down on to the chair angrily | the fishermen cast a large net around a school of tuna | figurative : individuals who do not accept the norms are cast out from the group.
For typecasting, I always had the idea of moulding something into the shape that you want; that’s this sense (especially the third one):
4 shape (metal or other material) by pouring it into a mould while molten: when hammered or cast, bronze could be made into tools.
• make (a moulded object) by casting metal: a bell was cast for the church.
• arrange and present in a specified form or style: he issued statements cast in tones of reason.
Etymology:
Middle English: from Old Norse kasta ‘to cast or throw’.
Popular in Discussions
Other popular topics
Chat & Discussions>Discussions
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #elixirconf-us
- #advent-of-code
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #hex
- #security









