Fl4m3Ph03n1x
Learning Elixir, frst impressions ( plz don't kill me ! )
About me? ( if you have nothing better to do than reading about some random guy in the internet
)
Hello all, this is my first post in this forum, so I apologize is something is off.
I am rather a direct person with strong opinions, but don’t be afraid of me, I don’t bite !
Recently I have been learning Elixir for a job offer ( yes, apparently you can find jobs using this thing! I mean, you have to sacrifice a virgin and a goat [ it can be a virgin goat ] to the Gods of Old and pray for 7 days, but hey, if it works it works right ? ) and I have been ramping up in my Elixir knowledge by watching as many conferences as possible.
I have a strong JS background where I do FP ( yes, it is possible ), and I got lured into this language becasue of it.
I have a lot of questions so I am giving this forum a chance!
Source
This 1 hour video covers the main aspects of Elixir and makes sure you have a lot of questions after. Suffice to say you won’t learn Elixir in 1 hour, but it is a good start I guess.
The following points summarize what I learned.
Elixir Facts
- It has modules. Modules contain and organize functions, so it’s cool.
- It has a ton of data types, most notably: Int, Float, String, Atom, Tuples ( arrays ), Lists, Dictionaries, etc.
- Int type is not bounded. It has no maximum nor minimum value. If you ever had an overflow using Node ( like me ) you will really appreciate this feature.
- Has a native pipe operator !
|>JS is being left behind
- Has native String concat operator
<> - Has native List concat and diff operators ++`` and
-- - Has destructuring !
- Functions can have the same name as long as their signature is different !
- Has anonymous functions
- Has no for loop constructor. WHHHATTATATAGGAHHAHAGATIhvgdjfsAVSGBZ
- Creates child processes easily and sends messages between them easily as well
Elixir Cons
Not everything is nice with Elixir. It also has it’s technical shortcomings:
- No partial application and no currying. This is something I would expect from a FP language ( like Haskell ) to natively support. Huge disappointment.
- Currying and partial application via anonymous functions have a weird syntax. Yes, you can make a library to workaround this flaw, but the syntax you need to use is … weird at best: Function currying in Elixir
- Being functional, Elixir has an horrible API. Most of it’s native functions are data first, instead of data last ( a basic concept of FP languages ).
- No Monads. Again very disappointing.
Elixir Weirdness ( aka, stuff you will eventually get used to )
- No return statements
- Elixir also has default values for parameters, but the syntax is anything but intuitive.
(x // 1, y // 2), this signature is saying that the default value forxis 1 and foryis 2. For most people, this would be a comment… - It has a short syntax for functions ( like the arrow syntax for JS functions ) but it is super cryptic.
Overall opinion
I know I am just starting. But aside from the data types ( that are immutable by nature ) JS actually has better support for the functional paradigm than Elixir. The native API ( String API comes to mind ) was designed using data first instead of data last ( a most basic flaw in an FP language ) and using currying with partial application feels clunky as all hell when compared to JS. And there are no Monads either … I mean Swift is not a FP language and even it has the Maybe Monad. How disappointing.
I must say I expected more from a newly designed FP language. The support for currying and partial application is rather atrocious but I can live with it.
I still didn’t get into error handling, but from what I have seen, it is extremely imperative with good old try rescue blocks. It would appear that basic knowledge from Promises and Futures is missing.
Questions
Or perhaps I am missing something? Allow me to rephrase my noob rant in an organized manner:
- How does one use Monads in Elixir?
- Is it possible to use currying and partial application in Elixir using the function normal syntax, instead of the
.(x).(y)syntax? - Are there any libraries widely used and publicly available to for the use of currying and monads?
- Are there any libraries that improve upon the mistakes of the native API?
- Is there a version of NPM or Ruby Gems for Elixir ( I understand there is none so far ) ?
Please let me know if I missed something. I have only seen a a couple of conference videos, I may very well be missing something brutal.
Most Liked
joeerl
The good thing about Elixir (and Erlang) lies in the concurrency - it’s all about creating parallel process and sending messages - and this (as Alan Kay has pointed out on numerous occasions) is the
essence of OO programming.
OO programming is all about objects. Objects are things that respond to messages (or should be) - to get an object to do something you send it a message - how it does it is totally irrelevant - think of objects as black boxes, to get them to do something you send them a message, they reply by sending a message back.
How they work is irrelevant - whether the code in the black box is functional or imperative is irrelevant - all that is important is that they do what they are supposed to do.
Unfortunately the first big OO language based on this model (smalltalk) talked about objects and messages but messages in smalltalk were not real messages but disguised synchronous function calls - this mistake was repeated in C++ and Java and the “idea” of OO programming morphed into some weird idea that
OO programming had something to do with the organisation of code into classes and methods.
Erlang and Elixir support the lightweight creation of millions of isolated processes - everything works by messaging between processes - the design of a system involves observing the concurrency you want in your application and mapping it onto processes.
A web server in Elixir for 10,000 users is not “one web server with 10,000 users” (like Apache or Jigsaw or all the rest) it’s “10,000 web servers with one user each” - this is a radicle departure from conventional practise.
The fact that Erlang/Elixir processes are described in a simple functional language is more or less an accident - they started off in a relational language (Prolog) and C-nodes (for example) can be written in ANY language - the important point about Elixir (and any BEAM) based machine is that the underlying VM can handle extremely large numbers of parallel processes.
For a long time I’ve said “Erlang is the only true OO language” (now I guess I can add Elixir).
The basis of OO programs are:
- isolation between objects (we do this)
- late binding (we decide what to do when a message arrives at a process)
- polymorphism (all objects can respond to the same message, for example, you could
think of sending a "print-yourself" message to any object and it would know how to do it)
Of lesser importance is
- division into classes and methods
- syntax
- the programming model (ie functional or imperative)
Once we have split a system into large numbers of small communicating processes the rest is relatively easy - each process should be rather simple and do rather little wich makes
programming easy.
What Erlang (and Elixir) added to programming was the idea of the link. This was Mike Williams idea - this extends error handling over process boundaries and with links and process we have all we need to build supervision trees and so on.
Supervisors, gen_servers and all that jazz are just simple libraries that hide a bit of detail from the user - they are just built in a rather simple way with links and parallel processes.
Erlang was not designed as a FP language - but as a tool for building long-lived
fault-tolerant systems.
Central to fault-tolerance is the notion of remote error handling. If an entire machine fails the fault must be corrected on a DIFFERENT machine. It cannot be corrected locally because the local machine is dead.
This means that to program for fault-tolerance we need distribution and messaging to be easy to program - so basically any design for fault-tolerance will end up looking like Erlang.
The whole point of Erlang was to make it easy to program fault-tolerant systems, a side effect is that it’s also easy to program scalable systems.
The differentiator between Erlang and Elixir and “All the rest” is the concurrency and fault-tolerence mechanisms - it not about Monads and Syntax and whether it’s a pure FPL.
Now would you like to handle 10,000 users in a single thread using callbacks to emulate concurrency or would you like to make 10,000 concurrent processes, each of which is simple and has no callbacks.
Each process waits for a message that it is interested in then performs a computation and sleeps waiting for the next message.
I think a big problem in evangelising Erlang/Elixir is that you have to explain how having large numbers of parallel processes solving you problem helps. Since no other common languages support concurrency in any meaningful way the need for it is not understood.
“But I can do everything in callbacks in a single thread” they’ll say - and they do - and it is painfully difficult - and you ask “what happens if the callback gets into a loop or raises an exception” - if they don’t understand the question you’ll have some explaining to do - if they do understand the question then you can tell them that in a strange far off land where was a was to program concurrency that did not involve callbacks.
joeerl
I guess I could shorten the previous posting.
Please don’t sell Elixir as an FPL - it’s not it’s a CPL (Concurrent Programming Language)
Don’t get into “my FPL is purer than yours” arguments. Don’t even think about talking about Monads. Change the subject.
“What’s a CPL?”
“You know, the kind of stuff the WhatsApp servers are written in …”
![]()
gregvaughn
Very good replies so far, but I’d like to step back for a brief historical overview that might help frame how you view Elixir in relation to other languages you know.
It is fundamentally a “concurrency oriented” language. Joe Armstrong (co-creator of Erlang) has described Erlang as such. Those design forces are reflected deeply in the VM itself, and it’s a property all languages on the BEAM share. The original reason for Erlang’s existence is that Ericsson needed a language to meet specific business needs. Fault tolerance was high on the list. Fault tolerance led to supervision which needed isolated processes (and basically independently discovering the actor model). Isolated processes needed immutable data and first class functions and tail call optimization. Thus functional features fell out of more primordial concerns. All of this pre-dates the creation of Haskell.
If you’re one that thinks proper “functional programming” has to include monads and currying, etc., then mentally put Elixir in a different language category or else you’ll remain frustrated. We have alternative means of solving similar concerns. They’re not as theoretically pure, but in practice work out well.
Everything I’ve said before applies to any language on the BEAM, so now let’s speak to Elixir specifically. It differs from its parent language of Erlang by adding Lisp-style hygienic macros and Clojure-style protocols. It adds the pipe operator from the ML family of languages and intentionally puts the subject first to optimize pipe use. It offers a superficially Ruby-esque syntax in some places (and differs strongly in others). It adds web development style tooling in libraries/packages via hex and in building/compiling via mix. There’s more, but that’s a good first group of things to digest.
There’s more to be said about intangibles like community. I find it quite interesting that you worry enough to put “plz don’t kill me” in your subject, and I’m pleased to see in the replies no inclination to even consider doing that.
Welcome!
Popular in Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance








