DEV Community

Camilo
Camilo

Posted on

Why I selected Elixir and Phoenix as my main stack

This is just a personal journey documentation on how I decided to use my current tech stack.

Over the years I have tried different frameworks, mostly in PHP, like Code Igniter (2010), ProcessWire (2014) and Laravel (2015).

They helped me complete different projects with diverse complexity. They are wonderful tools. But sadly most of the jobs I managed to land were using legacy versions of PHP and the codebase and developer experience was spartan to say the least. As an example in one project (2020) I had to connect to a remote Windows machine, edit the code in Notepad++ and then upload it using FTP. Odd workflows aside, I wanted to land more modern projects. So I embarked in a quest to find a new tech stack.

First I wanted to update my tools, maybe I just needed a small patch instead of changing them. So I made a project for a client using Laravel, Inertia.js Svelte, and then other project using Laravel, Inertia and React. I liked Svelte over React, so if future frontend projects appear, my main tool would be Svelte.

Both projects resulted in a superb improved developer experience and were finished in record time. A single monolith with backend and frontend did wonders because I did not need to create REST apis or GraphQL endpoints to make a fullstack system. Now I can have all the power of an SPA with all the good parts of a Backend, like direct access to a database.

I explored using Inertia.js as my main tool and made some adapters for ProcessWire, to understand better how it worked.

Vapor (Swift)

My first option other than PHP was using Swift and Vapor. I have made some projects with iOS and Objective-C, maybe I could also learn Swift and create both native iOS apps and backends with the same language.

But I discovered that it lacked the Inertia.js adapter, so I found this project

GitHub logo Lloople / vapor-inertia-adapter

The Vapor framework adapter for Inertia.js

Vapor Inertia Adapter

Vapor Logo Swift 5.2 Logo Build Status MIT License

This package is meant to help you using Inertia JS in your Vapor 4 project.

Features

Installation

Add the adapter in your dependencies array in Package.swift:

dependencies: [
    // ...,
    .package(name: "vapor-inertia-adapter",
            url: "https://github.com/lloople/vapor-inertia-adapter.git", 
            from: "0.3.0")
],
Enter fullscreen mode Exit fullscreen mode

Also ensure you add it as a dependency to your target:

targets: [
    .target(name: "App", dependencies: [
        .product(name: "Vapor", package: "vapor")
        // ..., 
        .product(name:"VaporInertiaAdapter", package:"vapor-inertia-adapter")
        ]),
    
Enter fullscreen mode Exit fullscreen mode

and created an example

Pros

  • Using Xcode to program a backend application was super nice, It was awesome to have an IDE with all the bells and whistles for the Swift language.

  • Coming from Objective-C was helpful to understand the Apple ecosystem and workflows.

Cons

  • I often have to resort to other editors such as VSCode to edit non well supported files such as JS, CSS or HTML files.

  • If you want to use XCode you need to use an updated operating system, if you have an older not supported Mac computer you will need to use Docker and use the Linux version of the Vapor framework, with poorer perfomance and developer experience due to using containers instead of Xcode.

Masonite (Python)

Masonite is a wonderful Python framework, much similar to Laravel I found in 2018. I even chatted with Joseph about it in the old Slack channels, before the community moved to Discord.

And there were some Masonite Inertia adapter too

GitHub logo girardinsamuel / masonite-inertia

Server-side Masonite adapter for Inertia.js

Masonite Package GitHub Workflow Status (branch) Python Version PyPI License Code style: black

Introduction

Inertia is a new approach to building classic server-driven web apps. From their own web page:

Inertia allows you to create fully client-side rendered, single-page apps, without much of the complexity that comes with modern SPAs. It does this by leveraging existing server-side frameworks.

Inertia requires an adapter for each backend framework. This repo contains the Masonite server-side adapter for Inertia.js You can find the legacy Inertia PingCRM demo with Masonite here demo (WIP).

Documentation 📚 Quick Start ⚡️

Features

Almost all features of the official server-side adapters are present 😃

  • Shared data
  • Partial reloads
  • Lazy loaded props
  • Set root view in a provider
  • Set root view per view
  • Enable sharing Masonite routes (prefer using masonite-js-routes)
  • Enable sharing Masonite flash messages

Official Masonite Documentation

New to Masonite ? Please first read the Official Documentation Masonite strives to have extremely comprehensive documentation 😃. It would…

Pros

  • I liked the way is well organized and the maintainer is super friendly.

  • You can leverage all the wonderful tools that Python has like PyCharm.

Cons

  • I did not like the way Python manage it dependencies, having so many options like Poetry or Pipenv, it feels non standarized as other languages.

  • Many of the available jobs for Python that I could find were either for Django based projects or Machine Learning stuff I didn't like too much. So using Masonite would only be for green field type projects.

Springboot (Java)

In university I learned a bit of Java, so maybe I could use it professionally I guess?. There were many options to choose from. DropWizard, Spark, Play Framework. But the more documented one in the internet I found was Springboot, besides there were some courses in spanish and some friends that knew something about Springboot, so I give it a chance.

I created some experiments like a simple Discord bot

GitHub logo NinjasCL / wrenbot

A simple discord bot that executes Wren code

Wren Bot 🪶

Seagull icons created by Freepik - Flaticon

Example Run Image

Ninjas.cl MPL v2 Tests

🚀 Environment setup

Requirements

application.properties

Configure your discord token and wren-cli executable path inside application.properties

Run

Execute

./mvnw spring-boot:run
Enter fullscreen mode Exit fullscreen mode

You can now send messages and it will return the output of the code.

☣️ Warning

Highly experimental, use at your own risk.

👩‍💻 Project explanation

Wrenbot is a small Discord bot created for testing out Wren scripts inside Discord.

📘 License

Unless explicitily stated, all source code is under the permissive MPL v2.0 (Mozilla Public License Version 2.0) license.

Is a copyleft license that is easy to comply with. You can combine the MPL version 2.0 software with a proprietary or differently licensed code.

  • If you don’t modify…

But I could not find an adapter to Inertia, just some POC, and I did not want to invest too much time in creating an adapter for it.

GitHub logo jrodalo / inertia

Spring Boot + InertiaJS Demo project

Spring Boot + InertiaJS

Demo project using Spring Boot and Inertia, because why not? :)

Running the App

To build and run the app, just type the following command:

./gradlew bootRun
Enter fullscreen mode Exit fullscreen mode

Then go to http://localhost:8080 and be amazed by the beauty of this PoC ;)




Pros

  • Highly robust framework, lots of documentation, courses and examples.

  • Super mature libraries and dependencies.

Cons

  • Most of the jobs I could find were for Banks and other "older" institutions. That have requirements such as going to the office (before C19) and even dress codes. I prefer to work remotely.

JavaScript

I already use some Javascript at the frontend, why not use it at the backend?. I tried Adonis.js because it was similar to Laravel, but felt odd to me. Also a client once required some bridge and I used Fastify.

GitHub logo NinjasCL / airnotifier-moodle-bridge

A replacement API for AirNotifier Moodle Plugin that connects directly to Firebase and other Push Notification Providers

AirNotifier Moodle Plugin Bridge

A replacement API for AirNotifier server for the AirNotifier Moodle Plugin that connects directly to Firebase, or others Push Notification Providers. This was made since newer versions of AirNotifier seems to be not working with the Moodle Plugin due to usage of old apis. This server implements all needed endpoints and acts as a middleware between Moodle AirNotifier Plugin and Push Notification Providers.

Installation

This server uses NodeJS instead of Python (Used by AirNotifier). Be sure to have NodeJS version >= 10 installed.

Also install Firebase SDK to your platform in order to obtain FCM Token or the other Client SDKs needed.

Configure

You would need to get the configuration from your firebase console or other adapters Check the index.js file for each…

Pros

  • I already knew Javascript and made some small apis and scripts.

Cons

  • There are lot of different frameworks out there. If you learn one, there is no guarantee that the next job you find will use the same. For example if you learn Express and the next one used Koa or Nest.

  • Already felt like a there were something wrong in Javascript, because there is always some breaking change that needs to rewrite the codebase or update the dependencies. I did not like that npm throws a lot warnings in the bootstrap of the project or installing deps.

Elixir and Phoenix

Ok so I previously toyed around with Elixir in Exercism and liked a lot the language. I found Phoenix framework but I did not understand it quite well.

A functional language took time for me to understand the conventions and workflows. It was like a whole new world.

Nevertheless I just waited some time before going fulltime as an Elixir dev. Accepting small freelance jobs in PHP and other small projects. But I decided to write in my CV:

"Would love to participate in Elixir based projects"

I really loved the idea of LiveView and how it wasn't needed a separate frontend framework to achieve a SPA like experience. So Inertia.js wasn't needed in the first place.

Although an adapter is available, before LiveView was created.

GitHub logo devato / inertia_phoenix

Inertiajs Adapter for Elixir Phoenix

Inertia Phoenix

Maintained by Devato

Tests Coverage Codacy Badge Hex.pm

Inertiajs Adapter for Elixir Phoenix 1.4 and 1.5

Usage

Getting started with Inertia.js in a few steps.

Installation

Add to mix.exs:

{:inertia_phoenix, "~> 0.3.0"}
Enter fullscreen mode Exit fullscreen mode

Add Plug to WEB_PATH/router.ex

  pipeline :browser do
    ...
    plug InertiaPhoenix.Plug
  end
Enter fullscreen mode Exit fullscreen mode

Import render_inertia lib/active_web.ex

  def controller do
    quote do
      ...
      import InertiaPhoenix.Controller
    end
  end
Enter fullscreen mode Exit fullscreen mode

Configuration

Add to config/config.exs

config :inertia_phoenix,
  assets_version: 1,          # default 1
  inertia_layout: "app.html"  # default app.html
Enter fullscreen mode Exit fullscreen mode

Render from Controller

NOTE: Flash data is automatically passed through to the page props.

def index(conn, _params) do
  render_inertia(conn, "Home", props: %{hello: "world"})

  # OR

  render_inertia(conn, "Home")
end
Enter fullscreen mode Exit fullscreen mode

Layout/Templates

In February 2022 I received my first offer as a fulltime Elixir developer, just because I said I liked to work with Elixir, no previous experience with it required!.

There I learned more deeply about LiveView and Surface UI.

Even took a course with Grox.io's awesome teacher Bruce Tate, It was an awesome experience. Highly recommended.

Pros

  • Elixir is a fun language. functional and fun to work with.

  • Is easier to find good jobs and be selected, comparing it to other markets such as Javascript were there are more job opportunities, but also more people to compete with.

  • The Erlang (1986) ecosystem is older than Java (1995). So is filled with lots of robust solutions to real world problems, like concurrency.

Cons

  • In my country there are few companies that uses Elixir (I hope that changes soon), but if you know english you can easily access international remote positions.

Conclusions

Why I selected Elixir?. Because I found it fun, functional and robust. And I landed a dream like job just because I liked the language, compared to other technologies that I have to create a "doctoral thesis" just to be interviewed. Elixir's job seeking experience was smooth.

That first Elixir job finished in October 2022 and after some small vacations I landed another dream like job soon after.

Elixir is a powerhouse both in the Technology side of things and the Job market side of things.

For me is the technology of the 2020's decade and much more!.

Top comments (11)

Collapse
 
sanjayojha profile image
Sanjay Ojha

Wonderful. I can feel many of these sentiments. Currently, I am trying to find a job, and I am intimidated by the current state of JS. Lots of entry level and college graduates trying their luck in the JS ecosystem. It has become overly competitive. It's hard to stay focused with too many libraries, frameworks, and tooling, plus the feeling of being outdated worries me a lot.

I am also a fan of Laravel and have developed a few of my clients' projects with it. I find it to be an absolute joy to be able to work with it. But the PHP ecosystem is losing momentum and getting a decent paying job (especially if you are from a third world country like India) is getting more difficult.

Not interested in Python either.

I will look into Elixir and see how it can help me to get a job. Aside from it, what other programming language would you recommend? Haskell? Clojure? Golang?

My main priority is to find a job in a less crowded programming language that has a bright future.

Collapse
 
clsource profile image
Camilo • Edited

Thanks for your comment!.
Elixir is surely a great investment. If you want to try other programming languages I recommend going functional using Erlang and maybe Gleam.

Gleam

The Gleam programming language

favicon gleam.run

Also Rust is a great investment too if you want to create native extensions for the Beam using rustler

GitHub logo rusterlium / rustler

Safe Rust bridge for creating Erlang NIF functions

Rustler

Documentation | Getting Started | Example

Build Status Hex.pm package version Crates.io package version Last Updated

Rustler is a library for writing Erlang NIFs in safe Rust code. That means there should be no ways to crash the BEAM (Erlang VM). The library provides facilities for generating the boilerplate for interacting with the BEAM handles encoding and decoding of Erlang terms, and catches rust panics before they unwind into C.

The library provides functionality for both Erlang and Elixir, however Elixir is favored as of now.

Features:

  • Safety - The code you write in a Rust NIF should never be able to crash the BEAM.
  • Interop - Decoding and encoding rust values into Erlang terms is as easy as a function call.
  • Type composition - Making a Rust struct encodable and decodable to Erlang or Elixir can be done with a single attribute.
  • Resource objects - Enables you to safely pass a reference to a Rust struct into Erlang…
Collapse
 
sanjayojha profile image
Sanjay Ojha

Never heard of Gleam. Will look into it. What is your thought for Golang?

Thread Thread
 
clsource profile image
Camilo • Edited

Golang is a cool language, but I prefer to use tools that are not depending on corporations to maintain them (Java {Oracle}, C#/Typescript {Microsoft}, Swift {Apple}, Golang {Google}), if there are better alternatives. Here is an interesting article about that.

Also in concurrency, languages based in the Erlang VM are light years ahead, IMHO.

Thread Thread
 
sanjayojha profile image
Sanjay Ojha

Thanks, my main concern is getting a job in less competitive programming language. I will check out all these options and will research a bit more. For now Elixir looks an ideal choice.

Thread Thread
 
clsource profile image
Camilo

Yes indeed. Elixir is a gorgeous choice!

Collapse
 
nexxeln profile image
Shoubhit Dash

Golang is great if you want a job as it's used a lot for newer backends.

Collapse
 
sanjayojha profile image
Sanjay Ojha

Ya, I am digging into Golang, but seems like people are ditching it in favor of Rust. I still have to find the cases where it outshine Rust. May be cloud application?
Not sure how good its for web development.

Thread Thread
 
nexxeln profile image
Shoubhit Dash

Golang is my least favourite language and makes me hate myself. The only place it outshines Rust is jobs. Very easy to get a high paying job in Go unlike Rust where you'll struggle to find jobs

Collapse
 
lionelrowe profile image
lionel-rowe

Assuming you've worked with TypeScript before at some point, how do you cope with lack of strong typing as compared to TypeScript? That's been the main thing that put me off putting more time into learning Elixir/Phoenix up to now

Collapse
 
clsource profile image
Camilo

Thanks for commenting!.

In Elixir there are some tools that help you overcome that lack of strong typing. Such as using typespecs and behaviours.

And also there is some plans to make progress in that area too

My Future with Elixir: set-theoretic types - The Elixir programming language

We announce and explore the possibilities for bringing set-theoretic types into Elixir.

favicon elixir-lang.org

Also if you like to work with a functional language that is type safe you can look for Gleam too :)

GitHub logo gleam-lang / gleam

⭐️ A friendly language for building type-safe, scalable systems!

Gleam logo

GitHub release Discord chat

 

Gleam is a friendly language for building type-safe, scalable systems!

It compiles to Erlang (or JavaScript) and has straightforward interop with other BEAM languages such as Erlang, Elixir, and LFE.

For more information see the Gleam website: gleam.run.

Sponsors

Gleam is kindly supported by its sponsors. If you would like to support Gleam please consider sponsoring its development on GitHub.

Thank you to our sponsors! Gleam would not be possible without you.

Fly.io