The Elixir of concurrency
cfenollosa.com
cfenollosa.com
Disclaimer I wrote a Udemy course on Elixir too, so if anyone wants a 30% here you go... https://www.udemy.com/elixir-for-beginners/?couponCode=Save3...
The issue really starts when you start writing web servers. I always advise that anyone who wants to start using Phoenix learns how to use Plug first. Phoenix is very macro heavy which can give that magic-is-happening feeling when you run your app, but looking through the Phoenix source code and using Plug is a great way of getting your head around what is actually happening behind the scenes.
Elixir is incredibly powerful and I find myself being more productive with it than with most other languages. TDD and integration testing is also surprisingly easy.
Phoenix does do an excellent job of getting people to try Elixir, kind of like how Rails did for Ruby. Phoenix has also added a cool abstraction in Presence/CRDTs. Now that people don't have to implement that themselves I wonder if that will be as useful to people like how ORMs stormed onto the scenes in the early 2000s.
I tried to learn Phoenix just after Elixir, and I just couldn't do it.
Now I've written a couple of simple web apps with Plug, and realized that I don't need Phoenix for most of my use cases.
I agree with web servers, check my reply below. Plug + Router is enough for most things, and even though everybody recommends Phoenix (maybe because many want to move from Rails to Phoenix?) I found it too complicated since I've never used an MVP framework, I'm more of a devops guy.
Finally, I didn't mention Elixir tests, but they are great. The lack of mutable objects helps a great deal too
Because in the end, the only "mandatory" part of Phoenix are Cowboy, an Endpoint. And that is all. If you use Channels only, you do not need a Router.
I recognize the benefit here but I have a strong aversion to this line of decision-making. "Current thing is maturing and becoming popular, now the community is unwieldy and full of riff-raff-- on to the next thing!"
I'm in the JS community and it is suffering terribly from this line of thinking-- every time something reaches any sort of scale & there are new, bigger organizational challenges, Thought Leaders jump ship to some newer, cooler, smaller project (or language). Lather, rinse, repeat, repeat, repeat, repeat.
Online communities are like this as well (see Reddit, Hackernews, Twitter, etc.). Only difference is the cost of moving from Reddit to HN is minimal for the user, the cost of learning a new language or rewriting an app on a new platform is HUGE for developers and organizations.
So I don't know elixer & if it's cool and worthwhile, by all means let's encourage people to use it, but NOT because it's new and the community is small! Beauty fades and if you're moving on to the next thing because it's young & doesn't have any warts yet, mark my words-- you'll be moving again soon enough!
The way I read that was: "most people are hesitant to try a new language with a small community, and lack of stackoverflow support, but here are some potential upsides of being in a small language community".
Not so much: "hey, you should switch to this shiny new thing just because it's new".
To the author, this is one of the best summary writeups I have seen on it, and I read every elixir thing that comes across hn or elixir radar. I think there should be more emphasis that just because elixir doesn't necessarily do computationally heavy stuff easily, there is nothing to stop you from using elixir as the job handler and then use something else for the heavy part.
There are also some things which I think might do well in elixir we might not think of. For example, on the irc chan I was told if you call a system call from elixir/erlang you lose the concurrency... so why not write somethings in elixir that were in system, for example, icmp/snmp query?
Regarding system calls and concurrency: Erlang does lots and lots of system calls. I think what that/those person/people were talking about are NIFs (Natively Implemented Functions) written in C. Those block the scheduler while calling out to C. However, that is a thing of the past with the implementation of dirty schedulers. AFAIK, Erlang/OTP 18 added better control of dirty scheduling and I think version 19 builds on that some more.
To follow up on your list of useful learning references, that talk from Chris is a bit old, but it covers all the basics. Nearly everything is still up to date. It is a bit long, but it takes time, cover everything and is not hard to follow.
https://www.youtube.com/watch?v=5kYmOyJjGDM
It was a workshop to teach the basics of Elixir at a Ruby conference. 3Hours long, but really great :)
>Neither developers don't want their code to crash nor Elixir promotes writing bad code.
Is this a double negative?
Not(x nor y) = (not x) or (y)
Ok, I'm done, I'll go and sit in the corner with the other pedants now.The pipe operator isn't Elixir's "novelty". Also, why is it better than the '.' syntax:
> fromFile(userInput).getLines.map(_.toUpperCase)
Do you get code completion for it as in an oop-ish language?
A |> B |> C second_param
Is the same as: C(B(A()), second_param)
It's much more powerful than that because you can create chains of functions that pipe their output i.e. Some_data
|> fetch_reports
|> email_users
|> setup_notifications
|> IO.inspect
|> affirm_elixir_pipes
It's 100% not the same as dot or arrow! IO.inspect allows you to print details of any data being passed but also returns the first argument passed.Hope this is a clear explanation of what is happening.
1. Bring everything down?
2. Try to capture the error and recover?
3. Kill the crashed process and launch another one in its place?
For example, C uses approach 1. Most modern languages
with Exceptions like Java and Python use 2.
No, in Java and C the "let it crash" (aka the "failstop principle") is also used.I thought we switched to a little more down-in-the-trenches discussion with you saying:
> The tools to watch, restart, etc are bash, ps, top, etc