Elixir from a NodeJs Developer’s Perspective — Part I
2 min readSep 20, 2021
I’ve decided to start learning and using Elixir.
My current playlist to getting started contains some books and videos:
- Elixir Casts
- Elixir Succintly via elixir-lang.org
- Introducing Elixir, 2nd Edition
- Metaprogramming Elixir
- The Little Elixir & OTP Guidebook Video Edition
- Learn Functional Programming with Elixir
- Designing Elixir Systems With OTP
- Testing Elixir
I will take notes and maybe share part by part.
Here are the first batch of notes
Notes taken during first Elixir session
- iex — the Elixir interactive shell is fast (considering that I was using NodeJs for long time anything is fast)
- https://elixircasts.io/ — perfect free getting started screen casts
Module and functions
- There are private and public functions: defined via
def
anddefp
. - Erlang functions, of course, can be used in Elixir.
- Reloading a module done via an internal function named
r
- Functions can take guard clauses to be used for anything but most helpfully to avoid returning unwanted values like via checking the arguments
- Same function name can be defined like java method overloading.
- Anonymous functions are possible (kind of arrow function in JS terms) but anonymous functions are called differently. with an extra dot before the parentheses. this improves the readability
- Anonymous functions can be created using
&
as following. The other ampersands are to define the parameters. &1 is the first &2 is the second ... argument.
- Inside an anonymous function we can call a function by appending the arguments to the given function.
- The same argument passing can be used for lists and tuples like. See the next image.
Anonymous functions concept or this entire functional concept is nothing new to a Js developer who has been adopted functional development in Js. But Elixir and JS is fundamentally different. Elixir is concurrent and Js is async.