wintermeyer
I am used to this syntax for a case structure (my question is about the _ -> part):
case {1, 2, 3} do
{4, 5, 6} ->
"This clause won't match"
{1, x, 3} ->
"This clause will match and bind x to 2 in this clause"
_ ->
"This clause would match any value"
end
A new team member introduced this into our project:
case {1, 2, 3} do
{4, 5, 6} ->
"This clause won't match"
{1, x, 3} ->
"This clause will match and bind x to 2 in this clause"
_other ->
"This clause would match any value"
end
So instead of a _ he/she uses _other. I do know that technically this is no different but I wonder what the majority does/thinks. I don’t want to tell that person in a code review that _other “feels” funny in case everybody but me does it. Every time I see it I stumble upon it but I understand why one would use _other.
Trending in Discussions
A little off-topic, but I feel like people here have a good head on their shoulders.
I used to be quite good at making software. Was luc...
New
Hi there! :wave:
@frigidcode and I (but mostly him) have been running an Elixir Book club, we’re almost done with Designing Elixir Syste...
New
I’ve been using Emacs as my main code editor for more than a two years. It’s a custom build version although I’ve tried doom emacs and sp...
New
There has been a thread to discuss the Stack Overflow Developer Survey on this forum every year since 2018, so here’s yet another one for...
New
I love Elixir. It’s one of 2 programming languages I’ve ever fallen in love with.
But I don’t use it anymore.
Serverless was the promis...
New
Lately I’ve been thinking about how to organize components as a LiveView application grows. One of the pain points I’ve found (for myself...
New
What IDE or editor are you using for Elixir development?
Personally, I use Zed, and I really like it, but sometimes I wish there were a ...
New
Other Trending Topics
Edit: 2026 May 15 - This post is archived.
Mob is alive!!
Main docs: mob v0.7.11 — Documentation
A bit of explanation for the slightly c...
New
Hobbes is a low-level distributed database for the Elixir programming language.
Hobbes provides a simple, safe, and scalable storage lay...
New
Hey. Is there anyone here who creates agents in their apps? Not talking about using agents, but creating them. I’m finding it pretty diff...
New
I fully migrated to my own harness from Anthropic/Gemini and I think it’s time to share it. Welcome DSH, the DeepSeek Harness, fully writ...
New
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
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
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #ai
- #podcasts-by-brainlid
- #ecto-query
- #blog-post
- #elixirconf-us
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #elixirconf-eu
- #api
- #forms
- #security
- #metaprogramming











Showing Posts 1 to 10- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
zachallaun
In this case, I would use
_because the word “other” adds no additional context or meaning.I do tend to prefer the named variant in function heads with multiple clauses. For instance:
This can be helpful especially with longer function heads that take, say, 4+ arguments, as multiple
_can get a little hard for me to parse visually.preciz
Actually I did use
_othera few times, but now that I think about it I probably just should have used_.It’s probably part of an inner monologue just like when people abuse the
thenfunction because it fits the inner monologue?sodapopcan
Just want to +100 this as it’s one of my biggest pet peeves. Like, no %#$@ it’s “other.” When it comes to scanning unfamiliar code, this type of thing is just distracting. If I see
_some_var, I think that something useful is being communicated. As already said,_otheras a catch-all is not at all useful.And, technically they aren’t equivalent as
_othergets bound whereas_doesn’t. I’m not advocating that is some sort of meaningful optimization, just sayin’dimitarvp
Yeah, I dislike
_otheras well but many others are valuable i.e. you have a long chain of matching that checks for several types of structs / maps and then ultimately it’s fine if below you have_not_a_map -> ...– and variations of that. A proper unused variable name really helps code readability.sodapopcan
Absolutely, that’s what I was trying to convey. Another way to look at it is that matching is basically (albeit not strictly) assignment—you wouldn’t called a variable
other(at least I hope you wouldn’t). So long as there is a name that makes sense I name my_s, which is the vast majority of the time.To take this a bit further, due to Elixir being dynamic I’d vouch for writing OP’s example like this (depending on context):
and if
nilis allowed, add a specificnilclause. This makes it very clear what is expected an errors out quickly if it gets junk.hauleth
With multiple clauses in pattern plain
_is even more important as:sodapopcan
Oh ya, good point!
You’ll at least get a compiler warning if you do that, though.
EDIT: wait, no you won’t since
_other, _otherbinds as I even pointed out earlieraxelson
You actually do get a warning in this case:
sodapopcan
Well I should probably stop snap-responding then
yukster
Kinda surprised no one else pointed this out but if you use Credo on your project (and you should) then – unless you’ve suppressed the rule – it will give you a warning for just ‘_’ and tell you to give it a more meaningful name.
Now “other” may not be the most descriptive variable name, but without better context of what sort of thing you are actually matching it will do in a pinch.
The TL;DR though is that Credo is the compendium of idiomatic Elixir choices and a bare underscore for a variable name is not idiomatic.