I would say more like 90% better just because I can appreciate a possible style guide that mandates with statements 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.
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)
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:
defmodule A do
def a do
with {:ok, a} <- do_a(),
{:ok, b} <- do_b() do
{:ok, b}
end
end
def b do
with {:ok, c} <- do_c(),
{:ok, d} <- do_d() do
{:ok, d}
end
end
def c do
with {:ok, e} <- do_e() do
{:ok, e}
end
end
end
The rule that a single-case with statement should always be rewritten to case did 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.
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.