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

New
rower687
Hi all, I’ve been reading a lot about the “let it crash” term and how supervising processes and the whole messaging passing make an elixi...
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
gausby
I asked this very same question on twitter and got some interesting feedback, but I thought it would be a good question to ask here as we...
1207 40165 209
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
matthias_toepp
I’d love to hear what people think about Wisp, the new Gleam web framework started by Gleam’s primary creator Louis Pilfold. Gleam, alon...
New

Other popular topics Top

baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
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
vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New
dblack
I’ve got an issue with an app and I’ve no idea of how to troubleshoot it. I’m hoping someone here might have seen something similar. I p...
New
sergio
Kind of like when jquery came out, it was super necessary. Existing drag and drop libraries have a bunch of baggage to support old browse...
New

We're in Beta

About us Mission Statement