sodapopcan

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

rvirding

Creator of Erlang

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 :wink:).

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 :wink:

These are just my thoughts.

12
Post #6
ryanwinchester

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

11
Post #3
Dusty

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.

10
Post #4

Last Post!

brettp

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’.

Where Next?

Popular in Discussions Top

AstonJ
Please see the new poll here: Which code editor or IDE do you use? (Poll) (2022 Edition) It’s been a while since we first asked this, I...
208 31695 143
New
AstonJ
I’ve just started the Phoenix part of the utterly brilliant online course by @pragdave. On generating the Phoenix app he uses the --no-ec...
New
PragTob
Hey everyone, this has been brewing in my head some time and it came up again while reading Adopting Elixir. GenServers, supervisors et...
New
lorenzo
Hey everone! I created a prototype for my app using Nodejs for the api. But the framework I chose wasnt great (in general theresnt any g...
New
nburkley
AWS re:Invent is on at the moment with some interesting announcements. One new feature in particular is the Lambda Runtime API for AWS La...
New
tomekowal
Hey guys! I want to create a toy project that shows a chart of temperature over time and updates every 5 seconds. I feel LiveView is per...
New
marciol
Please, let me know if this kind of discussion already took place in another topic . Hi all, how do you consider if is better to build ...
New

Other popular topics Top

minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
New
chrismccord
Phoenix 1.4.0 released Phoenix 1.4 is out! This release ships with exciting new features, most notably with HTTP2 support, improved deve...
688 31494 112
New
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New

We're in Beta

About us Mission Statement