I recently decided to start learning Elixir. I've already got a project in mind (I'm going to be converting some existing tools I use regularly on my systems from Python (a language I already have solid experience with) to Elixir since the concurrency model should help them be significantly more efficient), and I've worked through the whole 'Getting Started' guide on the website without any significant issues.
However, it's drastically different from most of what I'm used to (I'm coming from a mostly Python background, with some JS and SH experience), and I'm wondering if anybody might have some advice for people new to the language? Any particular gotcha's to watch out for that aren't well documented? Possibly things that need to be handled significantly differently in Elixir compared to other languages for efficiency reasons?
Top comments (3)
Heya welcome to Elixir ๐! I can't really pull any tips out of my head as of right now, but I've compiled a list of resources for you to checkout, so here goes!
P.S: With courtesy from ElixirForum (probably the biggest Elixir community forum?), you can sometimes get up to 40% off the learning resources! Just try to input
elixirforum
whenever you try to checkout :)In fact I've updated this to be in the sidebar's wiki of the #elixir tag,
In learning Elixir, it's important to think functionally. You're coming from languages that are traditionally referred to as object-oriented languages, but they still allow you to program functionally.
Functional programming might seem intimidating at first, but it's easiest to think about the difference with this simple JavaScript example:
Notice that in OOP, you have an object which has data and behavior (the
introduce()
function). In FP, you have an object with data, but its behavior is not a part of the object.So in Elixir you'd have a module
Person
, which defines a struct usingdefstruct
. It's best-practice to then implement functions in this module which accept an instance of the struct, and do something to/with it.You will witness this in many libraries in Elixir. Ecto's changeset functions are a great example. All of the validation functions in the Ecto.Changeset module accept an
Ecto.Changeset
struct and return an updatedEcto.Changeset
struct.My Elixir knowledge really took off after I read the book Programming Elixir โฅ 1.6: Functional |> Concurrent |> Pragmatic |> Fun. It starts with basic Elixir, but by the end of the book familiarizes you with complex topics such as Open Telecom Platform (OTP) and metaprogramming using macros. I now use it as reference when I need some clarification on concepts ranging in complexity.
Maybe watch some advent of code hacking from Jose himself
twitch.tv/josevalim/videos?filter=...