sodapopcan

sodapopcan

Throw away matches

I apologize if this has been discussed before, and I’m sure it probably has been, but it’s very hard to search for. I’ve been putting off asking about it for a while now, though, so I’m curious about this pattern:

_ = SomeMod.some_func("some_arg")

I’ve seen this in the docs before but the most prominent example I know of is the first two lines of the first function definition in Phoenix, here. If you aren’t a fan of clicking it looks like this:

# Warm up caches
_ = Phoenix.Template.engines()
_ = Phoenix.Template.format_encoder("index.html")

The best explanation I can come up with is that it’s signalling a side-effect. Is that it?? If it is, I find that kind of really nice, although perhaps at the same time it’s warmed me up a bit to typing (in Elixir) as it took me way to long to figure that out, lol.

But really, it is that it? If not, what’s up with this?

Most Liked

LostKobrakai

LostKobrakai

To focus the discussion. The warnings come from an (optional) dialyzer setting. That‘s why this approach is not present in all codebases, but just some.

hauleth

hauleth

Yeah, I often use such pattern to mark that I run that piece of code for sole purpose of side effects and I do not care about return value. So it will not be perceived as unintentional omission, but deliberate choice of ignoring returned values.

eksperimental

eksperimental

It was probably to avoid so kind of generated warning. If i see function that is not assigned or matched to anything I would assume it has a side effect, so I would not see the need for _ =.

Where Next?

Popular in Discussions Top

jswny
I would like to better understand what the advantages/disadvantages of umbrella applications are compared to structuring your app as as s...
New
mikl
I wanted to capitalize a string, and tried using String.capitalize(). That generally works well, until you try to capitalize a word like...
New
New
pillaiindu
In django there is a cache framework backed by memcached. Rails also puts a lot of emphasis on caching, and even the idea of russian-doll...
New
WildYorkies
It seems that the more I read, the more I find Elixir users speaking about all the ways that Elixir is not good for x, y, and z use cases...
New
AlexMcConnell
The reason that Rails is as popular as it is is because it’s very easy for relatively inexperienced developers to get a lot of work done....
588 19568 166
New
New
boundedvariable
I am going through the kafka architecture. All the features what the kafka is providing are already in Erlang. I would like hear your opi...
New
cblavier
Hey there, It’s been more than a year since we started using LiveView as our main UI library and building a whole library of UI componen...
New
pdgonzalez872
If this has been asked here before, please point me to where it was asked as I didn’t find it when I searched the forum. Maybe a mailing ...
New

Other popular topics Top

shahryarjb
Hello, I have map which I want to convert it to string like this: the map: %{last_name: "tavakkoli", name: "shahryar"} the string I ne...
New
jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod – where is this set? Thanks.
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 30877 112
New
jerry
Good day to you all. I have been struggling to get a query involving like and ilike to work. Can anyone assist me on this, please? pro...
New
vegabook
I’m brand new to Phoenix and I have stripped one of the demo applications to the bone. I just want to get an svg up on the screen. Here i...
New
freewebwithme
Using vs code and installed ElixirLS: support and debugger. And I got an error popped up on start up says Failed to run ‘elixir’ comma...
New
fayddelight
I tried installing elixir 1.11.2 erlang 23.3.4 via asdf in my zsh shell. Enabled the versions locally and globally. When I list them ...
New
AstonJ
We’ve put together this wiki for Phoenix LiveView - please feel free to add any info you feel is worth including. What is Phoenix LiveV...
New
joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 records...
New
Qqwy
Update: How to use the Blogs & Podcasts section You can post links to your blog posts or podcasts either in one of the Official Blog...
3271 126479 1222
New

We're in Beta

About us Mission Statement