4 ms·
I thought this was a great article! I've used Elixir professionally for several years and it all rings true to me. The bit about Keyword lists I think doesn't
by losvedir 3y ago
I thought this was a great article! I've used Elixir professionally for several years and it all rings true to me.
The bit about Keyword lists I think doesn't mention the biggest aspect of it as I think about it: erlang compatibility. I don't think they make a ton of sense in a vacuum, but a list of 2-tuples where the first element is an atom has been the convention for function arguments in Erlang for a long time, as I understand it. And so Elixir kind of adopted it as well, since it inter-operates with Erlang so much and so well. I think a good "map" implementation wasn't even available in the early days of Erlang?
So, basically I just kind of "go with the flow" and use keyword lists for the final `opts \\ []` parameter of a function, but basically nowhere else.
I also agree with `for` comprehensions. I use it when meta-programming function definitions, but hardly anywhere else.
Also, I forgot that `unless` even exists! I don't think I've seen it in any code since my ruby days 7 years ago.
- fuzztester 3y ago>Also, I forgot that `unless` even exists! I don't think I've seen it in any code since my ruby days 7 years ago. Pascal has both a while loop and a repeat ... until loop (and a for loop too, with to and downto variants, IIRC. And cannot remember for sure, but I think Unix shell has an unless statement, although you can use if with not too.
- rkangel 3y agoI agree on the origin of keyword lists but they do have a useufl property - the same key can appear multiple times. That's why they're right for varargs - because nothing stops the user using the same argument multiple times and sometimes (rarely) that makes for a good API.