3 ms·
Like many others, I disagree with more of these points than I agree with. I DO agree that you shouldn't wrap Enum functions inside of other functions, but I pre
by innocentoldguy 5y ago
Like many others, I disagree with more of these points than I agree with. I DO agree that you shouldn't wrap Enum functions inside of other functions, but I prefer using
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.
- devoutsalsa 5y agoIn cases where something really should be in the map, I like to use &Map.fetch!/2.
- nivertech 5y agoThis will work with both maps and keywords: 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.