sodapopcan
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
Trending in Discussions
Other Trending Topics
Chat & Discussions>Discussions
Latest on Elixir Forum
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
- #blog-post
- #phoenix_html
- #iex
- #graphql
- #ai
- #genstage
- #elixirconf-us
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #security
- #hex










Showing Posts 1 to 10- Show Best Posts
- Show All Posts (oldest first)
- Show All Posts (newest first)
ityonemo
I think @rvirding would be the one to answer this but I always personally thought of it as “casting into the unknown”. I smiled when I read thar. Possibly with an etymological relationship to “broadcast”?
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.
sodapopcan
These are all great answers! I was so stuck on the data conversion meaning that I didn’t even think about “throwing”. This gives me much relief, thank you!
Edited to add: re-reading this sentence from my original post

“However,
castwhen referring to “I’m sending out a message yet don’t want a response and don’t even care if it was received”” is now making me allrvirding
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:castmodels 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 thissendas well but then people could get mixed up between it and underlying message sending. Also some OO system yousendfor the synchronous object call.The name
callis 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 itcallis pretty good.In the older now deprecated
gen_fsmthe calls were calledsend_eventandsync_send_event.It is interesting to look at the code for the synchronous
gen_server:call. Check out thedo_callfunction in thegen.erlmodule. It shows how easy it actually is to get this reliability. It shows how right we got the primitivesThese are just my thoughts.
lud
Now I wonder, as a non native English speaker, why “cast” has been chosen to mean “type conversion of some data”.
derek-zhou
I am not native speaker either, I think
typecasthas special meaning in performing art. Eg: Clint Eastwood is often typecast as a cowboy.benwilson512
This is a great question with a fun answer! As I’ve heard it, the root of both “to cast” meaning to convert the type, and “to cast” meaning to throw or send is actually from the same context: Pottery. When you form a clay vessel this can be referred to as “throwing” or “casting”. This activity involves both the rapid spinning of the clay which gives us the “throwing” connotation, as well as the idea of giving something a form, which gives us the “typecast” usage.
Dusty
It’s quite a rabbit hole, actually. Here is a pottery site explaining the use of “throw” in pottery, from the old English “thrawan.” Presumably this led to usage in other contexts, e.g. “cast iron.”
sodapopcan
@rvirding Thanks so much for that detailed explanation! And thank you @benwilson512 and @Dusty for the extra info!