Elixir Expert — The Common Pitfalls in Elixir Coding

Malreddy Ankanna
blackode
Published in
8 min readMar 14, 2017

--

To fall is to raise

Photo by Jakob Owens on Unsplash

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…

Google Image Gif

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…

--

--

Malreddy Ankanna
blackode

Programmer & Writer, I write about coding, thoughts, ideas, personal musings, technical articles, and tutorials.https://bio.link/blackode