3 things I have noticed when giving courses[*] that people coming from a non-functional background can have problems with are immutable data, pattern matching, and recursion. But once you grasp them you never want to go back.
Robert
[*] It has mainly been erlang courses, and now elixir courses, but at this level they are the same.
I switch-hit between ruby and elixir all the time, and Iām constantly lamenting the lack of pattern matching now. I really donāt get how I did this for so long without it!
Iām not sure if this is a gotcha, but I find it difficult to read backtraces due to macros and/or anonymous functions.
Remembering the scoping rules. Iāve given up on that and now just assume everything creates a new scope⦠that seems to be the direction things are headed anyway.
Ruby muscle memory and spending minutes looking for where I forgot to type do.
The precedence of |> (also due to Ruby muscle memory and an unconscious desire for special syntax for functions whoās last argument is a function). Iāve definitely learned to heed the compilerās warnings on this oneā¦
Iām not sure if this qualifies as a āgotchaā per se, but I personally struggled with getting a complete grasp of the syntax. I donāt mean being able to use the syntax productively but rather the process unraveling the different macros and sugar and the different ways they can be represented.
Keyword lists and macros have already been mentioned above, which is really what I think this boils down to, but Iām talking about things like:
def add(x, y) do
x + y
end
Being the same as:
def add(x, y), do: x + y
Which can be:
def add(x, y), [do: x + y]
Which is really:
def add(x, y), [{:do, x + y}]
Which can be:
def(add(x, y), [{:do, x + y}])
And now itās revealed that what looked like a āstandardā function definition statement with some parameters and a function body is actually itself a call to a function.
I think there is a piece that Iām still missing with the add(x, y) definition really being something more akin to a value than a call, and when/how that conversion from a call to a value gets handled.
This isnāt necessarily a hurdle that you need to get over in order to become productive, but before you understand whatās going on behind the syntax little things can bleed through that may seem strange.
That was an interesting post and I learned something new today.
I sort of agree with you. My biggest gotcha with elixir is that there
are so many ways of doing the same thing and I have the habit of picking
the one which shots me in the foot!
Many of the examples donāt work. Many of the github projects, beyond the basic functionality that ships with Elixir itself, are abandoned or donāt work. Itās a huge problem when trying to evaluate how robust and mature the Elixir eco-system is for commercial adoption.
EDIT: Since I was asked for examples, I will list them here.
EDIT 2: My interest is in building a multi-node system that can do distributed processing of data in a ruby-style functional programming language. Data would enter this system via CSVs and Excel files (not just databases) and do extensive number crunching on all cores.
Can you please be a bit more constructive and show us some examples of ābasic things on github that donāt workā?
When I came to elixir, roughly at the edge of 1.0, yes I had this feeling as well, since I nearly found pre-1.0 stuff that didnāt work anymore with 1.0. But this happens.
This happened to me with rust as well, and also happens with ruby every now and then after there was a new āmajorā (in the sense of massive changes, not versioning schema) update.
Today, most of the old tutorials simply vanished from the net, or they have been updated. Or one can simply see by the date, that they probably wonāt help anymore.
Youāre not missing any piece, except for: def/2 is not a function, itās a macro, thats why add(x, y) is not a call to a function, and yes the AST for itās definition. You can give it a check on Kernel.def/2 documentation.
BTW, for me, this is one of the most awesome gotchas about Elixir: documentation as a āfirst class citizenā, if you allow me to pervert a little bit the āfirst class citizenā term. However, elixir documentation is just awesome, and having them offline, and easily, with the h/1 function on iex is just wonderful. This made my learning experience a lot faster and softer!