josevalim

josevalim

Creator of Elixir

Elixir had an option to choose either keyword lists and maps for options. The reason why we chose keyword lists are because they preserve user ordering and they allow duplicate keys. We use both features in Elixir itself.

For example, in try/catch/after, we warn if you put after before catch, as that would read weird. Using maps would not allow us to warn in those cases, as you always have alphabetical ordering.

When you do import Keyword, only: [get: 2, get: 3], those are duplicate keys. Keyword.__info__(:functions) returns duplicate keys too.

In other words, there are scenarios where keyword lists can be useful and unifying opts under keyword lists is reasonable. Community projects, such as Ecto, leverages them too. Plus other benefits such as Erlang compat.

28
Post #11
binarytemple

binarytemple

iā€™m interested, could you elaborate please

0
Post #12
NobbZ

NobbZ

ectos DSL relies on the fact that you can use keyword lists more than one time.

1
Post #13
ā€” All posts loaded ā€”