r/functionalprogramming • u/Voxelman • Aug 03 '24
Question What's the benefit of learning Elixir?
I'm currently learning Haskell (and F#), but I also look around to other languages.
One language that is often mentioned is Elixir. Do I have any benefit if I learn Elixir? It is dynamically typed, but I think strong static typing is a better choice to write more robust software. But maybe I'm wrong at this point and someone can clarify that for me.
47
Upvotes
45
u/FrijjFiji Aug 03 '24
Elixir is functional, but that’s not really its selling point. Where it excels is in managing huge numbers of parallel processes with relatively little overhead or boilerplate.
The most recent recent version of elixir introduced types under the hood, and I understand that they’re being made more explicit in future versions. Also, guards and pattern matching make it so that you can mitigate a lot of the downsides of dynamic typing in any case.
I work professionally with elixir, and I’m loving it. At this point it’s a mostly mature language better suited to production environments than most other functional languages. The BEAM (the virtual machine elixir runs on) is such a powerful piece of tech.
5
u/pthierry Aug 03 '24
I only used Elixir on hobby projects and I use Haskell in my current team, so maybe someone with more Elixir experience would answer something else, but in my case, Elixir helped me dive into the Actor model and the notion of supervision trees.
Haskell's primary tool for quality is encoding invariants in the type system in such a way that most bugs get the compiler to yell at you instead of the program blowing up in the user's face. My takeaway is that Erlang/Elixir's primary tool for quality is to make things always blow up in a controlled, recoverable way.
That's a precious idea to learn, IMHO.
"Systems that run forever self-heal and scale" by Joe Armstrong (2013)
12
u/clickrush Aug 03 '24
If you really want to form a grounded opinion I would suggest you use a dynamic functional language like Elixir or Clojure to write a program with an intended use case.
I don’t have much experience with Elixir specifically, but you’re generally choosing it for the runtime and the model of execution. It’s a language that tries to make the experience of writing on top of BEAM as pleasant as possible.
Generally speaking I‘m neither strictly for or against static typing. But having used both for different projects I find the main benefit of it is not correctness, but efficient, predictable performance.
To contrast:
Clojure has dynamic, strong typing but gives you the tools to write correct, simple code that provides guarantees which go way beyond what a static type system gives you.
TypeScript has static, weak typing. The main benefit here is autocomplete and documentation. But it doesn’t actually enable any more confidence in correctness or runtime guarantees than JS.
So really, static vs dynamic is not a hill to die on. Many of the most general and extraordinary claims of either camp are unfounded and lack real world proof.
If you want to develop a more nuanced opinion and be able to weigh the tradeoffs of different tools and languages then try them out in anger. That way you can say „it depends“ and ask „what are we optimizing for“ etc. instead of relying on platiudes.
You’re still allowed to have preferences and subjective options, but you can discern them way better from objective engineering concerns.
Bottom line: try it out!
6
u/dipittydoop Aug 03 '24
I'd say install Livebook and give it a try with some toy problems. The language is very pragmatic and easy to learn and there won't be any real sunken cost as the skills and habits will translate and be useful in any programming language.
The risk, in many cases, of the class based imperative OOP languages is that you can get into bad habits around mutable data or modeling abstractions. I'd much rather teach Elixir as a first language than Python/Ruby/etc for that reason.
3
u/[deleted] Aug 07 '24
I think there is a more mature take here, which is that there are times when dynamic typing provides a net advantage over static typing and vice versa. Elixir/Clojure/(generic lisp) all offer something unique to the table that I didn’t realize until I integrated into the ecosystem. Elixir and its “assertive” programming paradigm gives you guards that, if used well, gives you a lot of confidence that you’d find in a typed language.
Gleam is not like Haskell- they will not have type classes. They basically make the BEAM accessible with C like syntax.
I think elixir’s work towards gradual typing, introduced in its newest release, is work that will give you increasing type safety with the benefit of the flexibility it continues to provide.
1
u/[deleted] Aug 03 '24
I would highly recommend scala and zio, because it's the best and practical.
2
u/[deleted] Aug 03 '24 edited Aug 03 '24
Generally true but sometimes your problem can be solved comfortably with dynamic-type language that provide specialize primitive, also the virtual machine are said to be very fast (I don't really know).
While I am crazy with Haskell laziness and ADT, sometime I just feel more comfortable using Python for some jobs because of the familiarity of library (OpenCV)
If you are using lots of regex, you might love
perlorawkmore than other languages.(Not functional, but I digress) If you love learning about programing languages; Maybe you want to take a quick tour to postscript, just for fun.
https://webdocs.cs.ualberta.ca/~hayward/papers/BLUEBOOK.pdf
-2
u/a3th3rus Aug 03 '24
I'm not a fan of static typing. To me, it's too restrictive. I just write tests (mostly integration tests) for my code.
For me, the benefit of learning Elixir is just that it gives me lots of fun. The side-effect is that it lets me make money.