Why Elixir?

I would really love to collect some thoughts on this too so I can help companies not be afraid to adopt Elixir.

My big draws are Maintainability and Scalability

Maintainability

I watched the micropatterns talk, and Cameron really helps put to words the enjoyable parts of Elixir for me.

The quote from Scott Wlaschin was really insightful as well:

OOP has objects in the large, and methods in the small
FP has functions in the large, and functions in the small

What I take this to mean is that you attack small and large problems the same way in FP and Elixir, so problem-solving approaches are generally very consistent. For example, since Elixir is immutable, functions will transform data instead of leveraging state mutation where you can call a method on an object, and the object changes itself and/or other objects or their state that may not be in the same context of the developer. Over time all these OOP side-effects are forgotten and it becomes “less maintainable”. I don’t have to shift my problem-solving paradigms from “methods” to “objects” when it’s time to scale the solution.

Another point I thought was really helpful is that Elixir and pattern-matching tends to help developers architect for happy-paths. I’m not very familiar with railway-programming, but the idea that I’m gleaning from it so far is that we want to develop for the happy path, and tend to forget the unhappy paths, which is where our bugs usually show themselves. In Ruby, I usually encounter this as NoMethodError and always handling nil which makes it harder to grok the code.

def (%Employee{manager: %Manager{} = manager} = employee), do: happy_path()
def (employee), do: unhappy_path()

This is a simple example, but I could add more pattern-matching clauses to help me report better errors, or redirect the unhappy path to another process to make it happy.

Lastly about maintainability, because the Elixir community generally frowns upon meta-programming, you encounter less DSLs which are layers of misdirection. Rails is a huge DSL, so knowing Rails isn’t the same thing has knowing Ruby; knowing ActiveAdmin isn’t the same as knowing Ruby, but Plug is just elixir functions.

I think this leads itself to Elixir codebases generally being more maintainable. Would others agree? I feel that way so far, but I don’t have any psychology or data to prove that yet or make a point.

Scalability

My approach to creating software to solve a problem usually starts with having an idea for a solution. That solution starts small, but then as I dig into it, I realize it’s more complicated than I imagined, and that I might want to solve other domain problems at the same time.

If I chose something like Rails, I would have this feeling of impending doom that my app will get slow or is already slow, and then I’ll have to spend some time in devops to solve that problem; I’m not interested in devops like I am creating software. Whether that feeling is true or not is a different conversation-- I just feel that. I’ve also experienced issues forcing me to optimize old Rails code because it allowed my coworkers and I to be lazy with our SQL queries and architecture. If this app is commercialized, the company with that solution now has to determine what it has to do in order to keep growth going in order to meet goals. The question always comes up, “should we do a rewrite?”. A rewrite is rarely the right commercial answer, but developers at that point probably want to try new ideas in a safe place, and sometimes in a new language, so they’re really, really, really tempted to do a rewrite. A rewrite may the right professional development answer for that developer. Those opportunities don’t come often.

If I chose something like Elixir and Phoenix, I’ve never yet gotten the feeling of impending doom. I have felt the need to rearchitect some code, especially when Phoenix 1.3 released with DDD as a focus. But I felt like I had a safe place to try ideas when rearchitecting because everything’s a module with functions (see earlier point about maintainability).

The solution can start small, and I know that it can be scaled to enterprise scale. I no longer have to decide between a “productive language” or “enterprise language” when starting a project. I know this because it has concurrency out of the box, extremely good tools like mix, an incredible testing culture that’s also easy to test (since it’s all just modules and functions), and the base of a 30yr old language and OTP. And to boot, I can read Elixir just as easy as Ruby and understand the intention of the other developer.

summing up,
not all of these points I make are unique to Elixir-- you can find pattern-matching and immutability and great ecosystems elsewhere, but the magic is that the sum of all these small things build up to a greater language and ecosystem.

7 Likes