AstonJ

AstonJ

When you see code like this:

name = "José"

How do you read it in your mind?

In Ruby I would read it as:

name, is set to, José

In Elixir I’m not sure whether to read it as:

name, match, José

or

name, equals, José

How do you refer to it? Is there a ‘correct’ way?

Showing Posts 1 to 10

NobbZ

NobbZ

When there is just a single name, I do read it as “name is set to value of expression” while I do read it as “pattern is applied to expression”. I try to avoid to use “pattern matches expression” to avoid confusion with ===, which I often read as “left matches right”.

kelvinst

kelvinst

Yep, I would say name is set to José as well as in Ruby for single assignments. I know it’s not an assignment, but it’s easier to say, and comparing to other languages, the final result is the same of an assignment.

I never thought about compex pattern matching like:

person = %{name: "José"}
%{name: name} = person

But I guess the @NobbZ suggestions it’s pretty clear, the code could be described like:

  • “person is set to a map with the key name set to José”
  • and then “the pattern for extracting the key name from a map is applied to person”

Reading it afterwards, it feels very complex at the first glance (compared to imperative code when described), but I guess that someone with a little bit of experience in FP will understand everything, and will mentally compile it to the explained code.

peerreynders

peerreynders

Anything wrong with "José" is bound to name?

jmitchell

jmitchell

Pedantically, “set to” feels strange because it suggests trivial assignment without pattern matching. Like @NobbZ said, “match” could be confused with a strict equivalence check.

Elixir’s pattern matching is enabled by a unification algorithm, so what do you all think of “x unified with y”?

sotojuan

sotojuan

I like “bound” too. Simple and understandable.

AstonJ

AstonJ OP

Here’s a another one to throw in the mix:

name, is the same as, José

From this video.

After watching that video, I am leaning towards just saying:

name, equals, José

And just being aware that the operator can be used to assign variables as well as other things/pattern match - because they all boil down to making both sides the same/equal.

I’m also leaning towards this because = is in fact the equals sign :101: and calling it that just seems to make sense. (Can anyone remember when we first told to refer to the = sign as is set to - I distinctly remembering thinking that that’s weird, it doesn’t mean that it means equals! :lol:)

sztosz

sztosz

I think that it’s wrong question. I doubt you really translate in your mind = sign to a spoken word or phrase. I’m thinking in terms of symbols when I see symbols. Just like my native language being Polish, I don’t translate English text to Polish when I read it. And just as I read and think in English when dealing with English test, people etc. I think in “Programming” in general or “Elixir” in specific when I deal with Elixir code.

But If I was to read aloud this to someone I’d probably choose equals.

peerreynders

peerreynders

You are absolutely correct when it comes to the isolated character or symbol. But name = "José" puts that character in a context - and context can change everything.
:grin:

kelvinst

kelvinst

Well, thinking a little bit more about it, maybe we, programmers, are just addicted to the verb “to set”. If we get back to our math classes, we would find ourselves describing x = 1 + 2 as “x equals to one plus two”.

EDITED

Yes, it conflicts with == but I guess the context should give “equals” the meaning in this cases. For example if (a == b), do: IO.puts("hi") would be described as “if a equals b prints ‘hi’” and we would totally understand.

And in the conflicting cases like x = (a == b) it could be described like “x equals the value of the boolean expression ‘a equals b’”.

AstonJ

AstonJ OP

I do :lol: if I am reading through code and the sign is a standard character (so not something like -> or ~>) I automatically read it as such.

I’m not really keen on referring to it as different things in different contexts tbh (particularly as it might confuse newbies).

I think acknowledging/explaining that it does different things in different contexts is probably fine, particularly since it more or less does the same thing; it makes equal or tries to make equal both sides. What do you think?

I don’t think there’s a conflict as that’s two together, which I think makes us more attuned and open to accepting that it means something different (similar or related perhaps, but different). Agree?

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 92995 915
New
caslu
I want to open this thread for you all to discuss and help those who really like Ash but are still hesitant to use it in a real project. ...
New
mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
GES233
I’m posting this in response to Jose’s recent tweet (Cr. link) : People are sleeping on Elixir for a coding harness: Hot-code swappi...
New
marciol
It would be helpful to have a list of companies worldwide that hire engineers without prior experience in Elixir. Often, it can be quite ...
New
durvia
Anyone running long-lived stateful processes on BEAM? We’re building an AI agent runtime and would love to compare notes. We’re a small ...
New
AstonJ
This might be a bit disturbing for some but it’s happening - computers running on living human neurons. They’ve made them smart enough t...
New

Other Trending Topics Top

marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
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
Dmk
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
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
webofbits
Aludel - LLM Evaluation Workbench Aludel is an embeddable Phoenix LiveView dashboard for evaluating and comparing LLM prompts across mult...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews