Skip to main content

Gotchas

String​.to_existing_atom​/1 is a double-edged sword

·1143 words·6 mins
I’d argue Elixir has relatively few gotchas. It’s a simple and consistent language and when you first learn it there’s only a few things that are genuinely counter-intuitive and catch you by surprise. One of the examples could be the difference between binaries and charlists and why iex sometimes seems to do weird things to your lists: iex> l = [19, 7, 16, 119, 97, 116] [19, 7, 16, 119, 97, 116] iex> Enum.drop(l, 1) [7, 16, 119, 97, 116] iex> Enum.drop(l, 2) [16, 119, 97, 116] iex> Enum.drop(l, 3) 'wat' One of the other ones comes when you start working with atoms and get a little too trigger-happy with them. What you could hear from your more experienced teammates is something like this: