wmnnd
Apparently Credo considers single-clause with statements with an else branch a readability issue. I’m curious, what’s everybody’s opinion on this?
I think with can actually help readability when implementing a function with a “happy path”:
with {:ok, yay} <- something() do
this_is_the_happy_path(yay)
else
{:error, reason} -> handle_error(reason)
end
The alternative is, of course, to use good ol’ case:
case something() do
{:ok, yay} ->
this_is_the_happy_path(yay)
{:error, reason} ->
handle_error(reason)
end
Which option do you find more readable?
Trending in Discussions
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
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
Hi everyone!
The first release candidate for the Expert language server project is now available!
We’ve published a press release detai...
New
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
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
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 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
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
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
Hobbes is a low-level distributed database for the Elixir programming language.
Hobbes provides a simple, safe, and scalable storage lay...
New
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Just published claude-code-elixir, a plugin marketplace for Claude Code with Elixir support. These are the plugins I’ve been using for my...
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
- #podcasts-by-brainlid
- #ai
- #ecto-query
- #elixirconf-us
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #elixirconf-eu
- #api
- #forms
- #metaprogramming
- #hex










Showing Posts 1 to 7- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
benwilson512
Personal $0.02: For single clauses the case is 100% better because the patterns all line line up and stand out better.
stevensonmt
I would say more like 90% better just because I can appreciate a possible style guide that mandates
withstatements for consistent error handling. So that way you can easily identify functions that can return an error versus those that just return values that trigger conditional flow.AstonJ
I prefer the case as well, it’s much more natural (in the sense that even without knowing programming you would more likely be able to make sense of it)
tomekowal
Funnily enough. The same topic popped in recently when we were upgrading a quite old credo version.
We decided to get rid of the rule.
For me, it depends.
We have a bunch of modules where all the functions are pipelines and only one of them had a single case:
The rule that a single-case
withstatement should always be rewritten tocasedid not make much sense in that scenario. Other than consistency, I always pitch for using the simplest tool for the job. Case is simpler than with.cmo
Yes, if there is no
elseI usewithbut a singlewith/elseshould be acasein my mind.pdgonzalez872
I’ve seen matching in the
successcase work fairly well. So, your:would become:
D4no0
I agree with your case, I would also change credo rules. In my opinion credo is a universal tool, for beginners they should follow guidelines from default config, for advanced users they should tailor the rules for their needs. Credo saved me countless times when I was working with newbies, instead of me personally telling them when to use if or case or when, credo would guide them into a decent style, from there I could explain them the things that credo didn’t cover.