Hello,
I’d like to kindly ask about using case
vs. other statements/conditions.
I different languages (all OOP) I used if/else
most of the time. I didn’t use case
at all mainly because it needed break
and I found if/elseif/elseif/elseif/else
better readable.
I spent whole weekend on Elixir (great weekend! ;-)) and now I’m looking at my code and:
I used:
-
case
approx 50 times -
if/else
2 times forif x in some_list
andif x > 0
and looking at it now I might replace it by multi-clause function -
cond
1 time for:
cond do
n > length -> :error
length == n -> {:ok, ""}
true -> {:ok, do_something_with(x)}
end
And everything else is case
(not counting guard clauses/pattern matching in function arguments).
I even used case for stupid things like
case value do
[] -> :error
value -> {:ok, value}
end
Can anyone please tell me is this normal in Elixir or am I crazy / crazy love with case
?
P.S. this looks like funny joke question but it’s actually real and serious questions.
Kind regards,
Mat