by innocentoldguy · 5y ago · 0 comments
Map.get(foo, :bar, :some_default_value)
over foo[:bar]
because I dislike dealing with meaningless nil values, since they tend to be the source of bugs.I also disagree with not using else in a with statement. That advise seems a lot like, "Next, pull out your pistol and shoot yourself in the foot," to me.
Languages have idioms for a reason and a lot of these suggestions go against idiomatic Elixir, which I'd recommend against.
iex(1)> foo = %{a: 1, b: "test"}
%{a: 1, b: "test"}
iex(2)> foo[:bar] || :some_default_value
:some_default_value
iex(3)> foo = [a: 1, b: "test"]
[a: 1, b: "test"]
iex(4)> foo[:bar] || :some_default_value
:some_default_value
This looks like some Perl-ism/Ruby-ism.
I personally dislike truth-y/false-y values, as they do more harm than good, and making it harder for dialyzer to infer boolean types.Also Map.get/3 and Keyword.get/3 are probably faster.