sodapopcan

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

Showing Posts 1 to 10

ityonemo

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

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 #2
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 #3
sodapopcan

sodapopcan OP

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, 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”” is now making me all :man_facepalming: :man_facepalming: :man_facepalming:

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 #5
lud

lud

Now I wonder, as a non native English speaker, why “cast” has been chosen to mean “type conversion of some data”.

derek-zhou

derek-zhou

I am not native speaker either, I think typecast has special meaning in performing art. Eg: Clint Eastwood is often typecast as a cowboy.

benwilson512

benwilson512

Author of Craft GraphQL APIs in Elixir with Absinthe

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

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

Why is it called Throwing?

Origin of “To throw”: Old Engilish - twist, to turn, to propel.

Some potters describe their work at the potters wheel as turning. The Old English word thrawan from which to throw comes, means to twist or turn. Going back even farther, the Indo-European root *ter- means to rub, rub by twisting, twist, turn. The German word drehen, a direct relative of to throw, means turn and is used in German for throwing. Because the activity of forming pots on the wheel has not changed since Old English times, the word throw has retained its original meaning in the language of pottery but has developed a completely different meaning in everyday usage. Those who say they throw pots are using the historically correct term. Those who say they turn pots are using more current language. Both are saying the same thing.

sodapopcan

sodapopcan OP

@rvirding Thanks so much for that detailed explanation! And thank you @benwilson512 and @Dusty for the extra info!

Where Next? Top

Trending in Discussions Top

AstonJ
As the title says, please share what you’ve been up to with Elixir. Whether that’s been learning it, looking into it, making stuff with i...
2977 91898 914
New
AstonJ
The obligatory hello world thread! Who are you and where are you from? :stuck_out_tongue:
4616 55835 594
New
byu
@chrismccord : I just saw the Extract AGENTS.md from Phoenix.new into phx.new generator commit to the phoenix project. My initial shotgu...
New
arcanemachine
I was working on an Ecto migration and I needed a timestamp. So, for the nth time, I looked up the different data types for timestamps, a...
New
alexslade
Fly’s CEO posted this recently - Turn And Face The Strange · The Fly Blog It says that Fly is going all-in on sprites, which is a worry ...
New
Herve37
We’re evaluating API mocking tools for OpenAPI-based projects and would love to hear what other teams are using. We’re particularly inte...
New
matt-savvy
Is there a word for the ~> symbol used in Version strings? Do you also just call it a Squiggle Arrow™ ?!
New

Other Trending Topics Top

JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
mcass19
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve. They are GUI (Emerge) and State management (S...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
ausimian
Emily is an Elixir library that runs Nx computations on Apple’s MLX. Install it as the default Nx backend and Nx, defn, Axon, Nx.Serving,...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews