The Elixir language is cool. It's a functional language, first released in 2011, and gaining traction lately especially in the Ruby community. Elixir's syntax is inspired by Ruby, and its popular web framework Phoenix is reminiscent of Ruby on Rails.

Elixir is built upon the Erlang virtual machine, which means it inherits many of the superpowers that Erlang is good at -- namely, building large, scalable, fault-tolerant systems. In Elixir, and in Erlang, threads are extremely lightweight and cheap, so they're used all over the place. The Phoenix web framework was able to manage 2 million websocket connections on a single (very large) server.

One of my favorite Elixir features is the pipe operator:

# The normal way:
String.ends_with?(String.reverse(String.capitalize("freddy")), "F")

# The pipe operator way:
|> String.capitalize()
|> String.reverse()
|> String.ends_with?("F")

My other favorite feature is pattern matching, which, among other things, lets you do things like write multiple versions of a function and let the language figure out which one to call:

defmodule Greeter do
  def hello(:jane), do: "Hello Jane"

  def hello(name) do
    "Hello #{name}"

Pattern matching also works to pick apart data structures, similar to JavaScript's destructuring:

{result, value} = {:ok, 2}
# result will be :ok
# value will be 2

And if you've ever had to work with binary data in a language like C, shifting bits and masking to get at the bits you want, Elixir's binary pattern matching is mindblowing πŸ˜„ Here's a nice tutorial on binary pattern matching showing a function to parse PNG files in only about 40 lines of code.

I've must say, I haven't spent a ton of time using Elixir and Phoenix yet, but I'm pretty excited about both.

Show all replies

Hah, of course πŸ˜„I probably should've called that "the functional way" or something. I forgot to mention that Elixir is functional at its core, so there aren't any instance methods on strings or anything else! (it does have modules, though, which can group together related functions)

Reply to this…

(11 answers) Take me to the question