Adopting Erlang
adoptingerlang.org
adoptingerlang.org
In fact, Erlang was so simple I was able to read it before I even knew what it was. I learned it by digging into the RabbitMQ source code.
Pattern matching with function branching and case really changed the way I develop in every language. Just have a linear instruction flow, no more multiple returns, no more if/else, just read the code and when you're at the end of the function, you know what it returns.
Then, I fell in love with Elixir. The only language where macros aren't just C's #define to replace text. You're working directly with the AST, and that's just obvious to me now it should be done like that. Mix is also a game changer for the Erlang/Elixir ecosystem, it's so easy to build/release/deploy with Mix. I remember having some difficulties getting erlang.mk or rebar to work correctly, but with Mix it was instantly working. Also config/runtime.exs, I love you.
The OTP framework let's you structure your code the same way you conceptualize it in your head: "I have this part that talks to this part, and they need to know what this part is doing" translates to "I have a module that send messages to this GenServer, and they both monitor this process".
I can't understand why those languages aren't more known/hyped/adopted/... It's a shame.
It's hardly the only such language. In my experience, Haskell, Rust, Common Lisp, and Scheme all have macros that operate by syntax trees rather than text substitution, and I have no doubt that there are several more that I'm not aware of.
For Rust, I've seen more usage of `macro_rules!` than the other one (so much I did not even know it existed). And it looks a lot like C's #define.
But yeah, my bad, I've been a bit too presumptuous when saying Elixir was the only one.
[0] - https://chrisdone.com/posts/haskell-doesnt-have-macros/Circle compiler for C++, and D as well.
Don't get me wrong, Tcl metaprogramming is awful and gross and I don't recommend it, I was just being the stereotypical nitpick HN commenter for that moment since it CAN be done.
That being said, having learned Elixir, I struggle to imagine using anything else for a greenfield web application. However, I have some curiosity about programming languages and was willing to take a leap of faith based on a few enthusiastic HN posts. Not everyone is like this.
Let me add that you, yes you reading this post, should read Elixir or Erlang if you haven't yet!
No matter what language I'm programming (including elixir), my pseudocode in design documents is always written in a pidgin erlang. It's simple, direct, discourages side-effects and encourages composability. Its building blocks (and syntax) also make it easy to describe abstract data types and schemas.
The only things I didn't like:
* Message queues are fundamental to the abstractions. If you need to avoid queuing for whatever reason then you need to think harder
* Leaving the Erlang ecosystem (e.g. shelling out) always felt painful. Integrating with Kubernetes was painful. OTP has its own ways of doing everything and they are often counter to general best practices (e.g. doing hot releases instead of rolling new containers)
* I never figured out how to do multi-node systems correctly. One of the neat things about OTP is that you can migrate processes between nodes that are connected in a mesh network. The documentation is really light on how to do this. Along those lines, more advanced multi-node setups exist but feel like they are at the fringes of what has been done with OTP so you need to invest a lot of time if your application can't handle a mesh setup
The only language that comes close to Elixir for me is Rust. I haven't done much with Rust however the out-of-the-box tooling is really great for it. I'm doubtful that distributed applications are as easy to write in Rust as they are in Elixir though
I tried to sell a company I was working at (they were doing real-time bidding) on Elixir. It's a shame they didn't go with it (they went with Java instead). It's really easy to build those types of apps in Elixir. Likewise I'm somewhat surprised Elixir hasn't taken off with teams who want microservices.
- https://hexdocs.pm/rambo/Rambo.html
- https://hexdocs.pm/elixir/1.12/Port.html
- https://github.com/Pyrlang/Pyrlang
- https://github.com/goerlang/node
- https://erlang.org/doc/apps/erl_interface/ei_users_guide.html
- https://erlang.org/doc/tutorial/nif.html
> Integrating with Kubernetes was painful - https://hexdocs.pm/libcluster/readme.html
- https://hexdocs.pm/k8s/usage.html
> OTP has its own ways of doing everything and they are often counter to general best practices (e.g. doing hot releases instead of rolling new containers)Now this is opinionated. Hot releases are used mostly if you want to upgrade your drone's software while it's flying. Surely you don't want it to crash?
Or if you're a telecom company (like the creator of Erlang), you don't want an upgrade to kill the on-going communications. Same for a MMO, you don't want an upgrade to disconnect your players.
Docker/Kubernetes is not "general best practices". It's only one way out of many. And if you don't need the use cases above, you can put your application in a Docker container and restart it for upgrades, this is how 90% of Elixir/Phoenix webapps are deployed.
> One of the neat things about OTP is that you can migrate processes between nodes that are connected in a mesh network. The documentation is really light on how to do this.
- https://hexdocs.pm/horde/
- https://hexdocs.pm/highlander/Highlander.html#content
- https://github.com/ringling/distro
> The only language that comes close to Elixir for me is RustHow? They solve completely different problems. Could you explain?
> How? They solve completely different problems. Could you explain?
I don't disagree. The main crossover for me has been in productivity/expressiveness/safety. Can I easily write the programs I want to write with it or am I fighting the language and tooling constantly? Do I have high confidence in the correctness of my solution? Does the solution feel easy to maintain and extend? I haven't done enough with Rust to comment on how it fairs for larger projects, but my experiences with it for smaller problems has been very positive
It's pretty great to feel somewhat familiar with the code examples as a new Elixirist. They don't feel that alien, especially the GenServers!
From my superficial understanding, this would be an ideal use case for Erlang. I guess an Erlang environment would naturally lead to a much more elegant solution.
The problem is, that nobody really speaks it here or has any experience with it. That's why we chickened out and used Go and C++ instead.
I guess a lot of developers have the same problem. Erlang is intriguing, but other languages are the safe choice.
It builds firmware for Pis and other IoT on top of a thin Buildroot Linux layer, starts the Erlang VM and then that's practically your OS for building your device. Plenty of escape hatches for special needs.
I've done a bunch of streams recently with clustering Pi devices using Nerves, especially fun on local network with mDNS. They are on my blog: https://underjord.io/blog.html
Feel free to reach out if you have questions about Nerves. I'm an enthusiast of it, contributing mostly by using it for fun in public. Also write the newsletter so I'm fairly up to date :)
A lot of devs find Elixir more approachable/familiar than Erlang so it might help in your case there as well.
We are using the first boards from the final batch for this, and I really hope we can start shipping soon.
four of us decided to see if erlang would suit us better, and within three months we had learnt enough of the language to set up an mvp that was both outperforming and out-uptiming the python cluster, with significantly less code, and all in basically 10-15% of our time, since we had to do our actual work.
sadly management decided that erlang was too risky to bet on, but my takeaway from that experience is that it is a remarkably easy language to learn/train even junior developers on, and that if your problem fits its sweet spot the language/platform will practically guide you towards a nice clean solution for it, and more than pay for the time taken to learn it in reduced maintenance complexity.
If Erlang is uncomfortable, then use Elixir. Here is an IoT project using Elixir: https://www.nerves-project.org
Basically enterprise IT sometimes mistakes something being easier to finish with it actually being simpler to run long term. Hence people who write themselves into corners with Python websites etc
Should probably check in with elixir again. Although we’re plenty happy with golang at the moment…
This getting started guide also covers some more examples of working with strings (vs. charlists, the erlang string type, which are described at the end): https://elixir-lang.org/getting-started/binaries-strings-and...
Yes, the Elixir stdlib uses only binary strings, never charlists. But to be fair Erlang largely got its shit together with binary strings a decade ago.
After the confusing terminology was out of the way and I understood the underlying systems, it all felt fine. Has a learning curve though!