DEV Community

Cover image for Elixir in the eyes of Node.js developer
Luke Czyszczonik
Luke Czyszczonik

Posted on

Elixir in the eyes of Node.js developer

Cover photo by Kaizen Nguyễn on Unsplash

I got into Elixir some time ago, but at that time, I was more interested in statically typed languages. I didn't exclude Elixir at that time, but instead, I moved it to a second plan. One of the signals to give Elixir a try was the talk from Saša Jurić - The Soul of Erlang and Elixir. I highly recommend watching this talk. I discovered that the BEAM VM and Elixir features could offer many benefits. So I decided to try and see how all the pieces are working together in an actual application. I'd like to share some critical ecosystem points that convinced me to try.

  1. Community
    One of the first things that I noticed when I started was the community libraries. Almost all the libraries shared the same structure and had all the API interfaces generated along with the type spec. So I searched for a few libraries that I often use, like web framework, GraphQL implementation or Database management. I can say that all of them look solid, and the documentation also contains a lot of guidelines, so I didn't need to leave the page to have a good understanding of them.

  2. Phoenix framework
    The Phoenix is a web framework that makes building web servers easy and fast. Great thing is that Phoenix has a built-in code generator. This generator is done via the mix task and you can generate almost all needed parts for creating an endpoint, context or database schema. Additionally, the documentation and guidelines described in the next point make you much more comfortable in the first place.

  3. Testing and documentation
    When looking back on different projects, documentation and testing are some of the forgotten things during development. Within the Elixir, those things are built in the language, making a considerable change for development and maintenance. You can write the documentation and examples right next to the code, and as we advance, you can turn these examples into quick tests. It was a nice thing that convinced me to write more tests and documentation.

  4. GenServer

    The GenServer allows you to abstract logic around small services. For example, all these services might have a separate state and business logic encapsulated inside. The service code is executed as a lightweight BEAM process, which is fast compared to standalone microservice solutions. Therefore, you do not need any extra HTTP layer or queue to communicate within the service.

  5. Type system, pattern matching and language itself

    I need to say that I'm a big fan of statically typed languages. So, when I heard about the Elixir for the first time, missing a type system was a big downside for me. Also, I understand that making such a dynamic language static would be a big challenge. To fill this gap, I used Dialixir and Typespecs. The experience is slightly different, but you have some tangibility of the type system, called success typing.

    Elixir has a functional language style that fits my personality best, but everyone can feel differently. On top of this, you have a great set of language features like With statements, function guards, the pipe operator and excellent pattern matching.

  6. BEAM virtual machine
    I think it was one of the biggest deal-breaker for using the Elixir heavier. The BEAM architecture, combined with the language features described above, make it a great combo!
    The virtual machine is responsible for running your code in small, cheap and fast processes. One of the philosophies that are coming from Erlang is Let it fail. The philosophy allows writing the system that is working more consistently and reliably. I could compare this to our systems like Linux, Windows or macOS. The system is working, but some programs that we installed are crashing from time to time, but usually, your system is still working, and only what you have to do is open your program once again. Like BEAM VM, one process might crash, but the whole system is still working as usual.

    Overall, I feel surprised how good working with Elixir was. One of the gaps is the lack of a static type system. To fill this gap, I used Credo, Dialixir and TypeSpecs to analyze the codebase statically. The language features make writing the code quicker, easier and cleaner to maintain. For example, built-in documentation and testing might turn your codebase into an environment that is a pleasure to work with. The last piece of this whole stack is that all of this runs on BEAM VM, which is the cherry on the cake! So I need to say that the lack of a static type system is no longer a significant disadvantage with such a combo!

    It is the first blog about my elixir journey, and I plan to share more detailed knowledge soon in my next blog.

Top comments (4)

michaelwills profile image
Michael Wills

Thanks for posting this! And particularly the talk from Saša. The demo was eye-opening. I wish I had tooling like that for many projects. And the summary at the end is spot on.

The Soul of Erlang and Elixir • Saša Jurić • GOTO 2019

czystyl profile image
Luke Czyszczonik

For me that talk was the deal breaker :D

dkuku profile image
Daniel Kukula

Check hammox-the initial setup may seem complicated with all the behaviours stuff but it can help you with checking functions input and separate views tsts from business logic tests

czystyl profile image
Luke Czyszczonik

Seams quite interesting and fits the Elixir DX so I'll definitely give it a try. Thanks!