Elixir Expert — The Common Pitfalls in Elixir Coding
To fall is to raise
This article is all about common mistakes of newbies in Elixir. Even experts in Elixir some times fall under this category. From the experience, I am revealing some sort of things to be careful while coding. This doesn’t mean that you fall in this category. I am just saying there are pits and you do not fall into it. Don’t worry I am just kidding. Lets jump into virtual pitfalls…
1. Functions with |> operator and parameters
This is the most common pitfall and one has to be more careful while piping the functions with parameters which leads to unusual results. Lets check the following example.
String.graphemes "hello" |> length
When you execute above line, you will get an ArgumentError
. This is because the above lines are grouped as follows
quote(do: String.graphemes "hello" |> length) |> Macro.to_string
"String.graphemes(\"hello\" |> length)"
So, you can use quote
and Macro.to_string
to see how your coding lines are grouped together. We think in the direction of output of…