Elixir lang 1.10.0-rc0
github.com
github.com
The main positive I see is that I can easily navigate through code (due to absence of complex objects/classes) and the standard library seems to be very extensive.
The language was also easy to get into. My only complaint is that the IDE support for intelliJ(through the plugin) hasn't been impressive though I can live with it.
Coming from an object oriented background the idea that classless code could be less complex is sorta blowing my mind!
You can call into a module with a variable, but it's rarely done, outside of some specific types of code interaction (ex: structural event loop processing like gen_server takes a Module to callback into).
Of course, when sending messages to processes, there's not really anything in code to indicate where those will be processed, and I don't know that IDEs help there either. Usually, code organization helps, but it's not required.
Caveat: my experience is with Erlang, not Elixir, but should generally apply.
Not to mention, there's not much boilerplate to deal with and we've got useful control structures like the very readable `cond`s instead of if {} else if { } blocks (Although you can use these, it is generally discouraged in Elixir). I will tell you that being pushed towards writing "cond" s and "when"s, "with"s has guided me towards achieving a better and more readily understood codebase.
In Erlang, the few simplifications you get are very local (as long as you don't apply a parse_transform on your whole project, which is rarely a good idea).
I never wrote a macro in Elixir (only for experimenting with them), nobody ever did in the projects I worked on and I'm perfectly happy with that. On the other side everybody uses macros, mainly with/do/else. I wish they implemented it as keywords of the language. They could probably have spared us the annoyance of converting code from = to <- and comma everytime it is moved inside a with and viceversa. That's the part of the syntax that I like less.
- I'll say that Phoenix Macros somewhat annoy me, but i can see why they would be useful for someone with a Rails background (which I am not).
- I'm quite happy with not having to think about how Ecto marshals its queries into SQL. Life's too short for that.
- Is it really such an impediment to code grokking to have a `test "label" do...end` construct?
https://pragprog.com/book/jgotp/designing-elixir-systems-wit...
It was hugely helpful to me in wrapping my head around something bigger than hello world.
I've dug into Ecto, Ecto SQL, Elixir itself at times. This was just because I was trying to figure out some corner-case behavior. The overhead of understanding someone else's classes when I tried similar things in Python was always just a much heavier mental load. Idiomatic or not.
As mentioned by another comment, the important thing is that each function you need to read can pretty much be read on its own. You might need to follow a few trails. But the way a library can hide where the magical state comes from in a Python class is sometimes maddening. I know, because I've written that code.
I find Elixir incredibly readable, nicely writable and the mental overhead continuously lower.
I've written a project that uses macros heavily as well and it's hard to make it easy to understand.
It's a double-edged sword. Macros are nice and can simplify the top-level API significantly, but at the same time they add complexity under the hood.
I like them for use in some bigger frameworks but overall, they seem to provide negative value to me as a reader, often confusing names doing some magical coating which could very well be solved with pure function composition.
I have noticed some python projects making heavy use of it... they rely on you to read their guide to write code instead of switching and using the project fine because you know the language. Sort of like another DSL?
Elixir hits the balance for me between being not too intense (haskell) and friendly usable with a nice community.
One hurdle that was difficult for me was understanding Behaviors (which are an abstraction used in both Erlang and Elixir). On the one hand, a Behavior is much like an class/object: it has public methods, internal state, polymorphism (via message passing) and to some extent a notion of inheritance. According to Alan Kay, it's more Object-Oriented than Smalltalk!
However, a Behavior runs in it's own process. Like a typical class, public and private functions are defined in the same file This makes reading the code where a Behavior is defined more difficult because the public methods are executing in the client process, but the callbacks (i.e. private functions) are executing in the Behavior's own process.
One insight I gained from working with Erlang was that the "academic" notion of OOP modeling (i.e. model the entities of your domain as discrete objects) works much better with Erlang's proceses/Behaviors than it ever did with classes/objects in languages like Java.
Objects in languages like Java, C#, Ruby, JS, etc. are much at modeling the architectural components of a system, than at actually modeling domain entities directly. That's actually partly why I really the Pony language: it combines both objects as processes (called Actors) and objects as components/capabilities (called Objects).
This doesn't sound right; a behaviour is just a set of functions to be implemented in a 'callback module'; you seem to be talking about processes and modules. I agree with your points though.
Going back, I see that you are right: the Behavior is technically the common pattern that is shared across specific processes. Is there a name for a process that is defined in a callback module?
And really, this complaint about confusing modules spans to more than just callback modules. Most processes define both the client and server functions in the same module. For small modules it's not too big a deal, but even then it is very difficult for someone new to the language to learn how follow the flow of data.
Dave Thomas has some interesting ideas about this and other problems, but as I don't do Erlang programming professionally at the moment I haven't had time to really dig in deep.
I don't think there really is. Where I was working, we would just say this process is a gen_server (or whatever), as if it was a type of process, but this is more of an emergent property of the environment, than a named property. If enumerating the processes, you can guess a process is a gen_server based on erlang:process_info(initial_call, Pid), but that's not definitive because it could have started as something else, then used gen_server:enter_loop to become a gen_server, or started as a gen_server and then become something else.
Naming the behavior the same as the module, and including client apis and server and the behavior in the same module is legitimately confusing as well; although, all that being in the same place can be nice, too.
However, it is the case that the most commonly used behaviours are gen_server, gen_statem, supervisor, etc, which do live in their own processes, and it is arguably most useful to use behaviours to determine the callbacks that an abstracted, general process-managing module uses to hook into the module you write that describes the implementation of a GenServer.
For an example of a non-process-bound use for a behaviour, one could have "ping" behaviour, which describes running an ICMP ping. You could then describe in abstracted form, the common points between an implementation that uses the linux standard ping, fping, a FFI call to low-level OS hooks and network stacks, a call to the new OTP 22 socket module. Or, in a test environment, write a module where it's backed by a stateful lookup table, where you can assume a ping response, but selectively turn off ping responses to IP addresses to simulate a failed ping response and verify downstream effects.
http://erlang.org/doc/man/ssl_session_cache_api.html
If you implement your own cache module (backed by a file, DB, whatever) and it respects this interface, you can then pass it to the SSL functions and they’ll use it instead of the default cache.
It just happens that gen_server is both the name of a behaviour, and the name of a module, which can be a bit confusing. The gen_server module implements a generic server process, which is customized by passing it a module that implements the gen_server behaviour (as an argument of `start_link`).
Mint (HTTP client library) - https://github.com/elixir-mint/mint
Jason (JSON library) - https://github.com/michalmuskala/jason
Tesla (Another HTTP library) - https://github.com/teamon/tesla
---
Yeah, the thing that has driven me to FP, and made Elixir/Erlang such a joy is that data and state are like not coupled (not saying they have to be in OOP, but god damn if I haven't had something that should only do a read do a write and fuck me too many times to count). Given the same input a function will always produce the same output, because values are constant. I've been writing Elixir for like 5-6 years now and four of them professionally, and I hope I never go back to a non FP language (save Rust or mind-boggling pay).
It's kind of mind blowing when you realize, at any point in your program, you can simply serialize out your data, inspect it. Try that with a class, good fucking luck with whatever marshaling system you have...
In Elixir/Erlang, all you (generally speaking) ever have are:
- Strings (binaries, bit-strings, charlists)
- Numbers (integer, float)
- Lists (a list of things)
- Maps (a set of keys and values)
- Structs (a map with a predetermined set of keys)
Recursion and pattern matching make for more readable code IMHO. Here's a fairly trivial snippet from the other day, of converting structs to maps (which Elixir doesn't do implicitly): https://gist.github.com/tehprofessor/fd8aebeb4804201a49f37d9...
The biggest thing to keep in mind coming to a BEAM language from somewhere else is that both the language you're using (Elixir/Erlang/LFE[1]/etc) and the runtime were explicitly designed together to solve a specific category problem (distributed systems). This very unique combination provides, IMHO, the best environment you could ever want to run code in...
In most languages you start up your server in its own process. Want to debug it? You gotta restart the process and then put your debug point in. Not the case in Erlang/Elixir, here's how I start up the Phoenix framework:
iex -S mix phx.server
What that does is both (a) starts the server, (b) opens up an interactive repl for the running application. You can then interact with the running system as it is, and holy shit does it make debugging wonderful.
Want a fast cache for that one operation but don't want to setup X, Y, or Z? Use ETS it's built in: https://elixir-lang.org/getting-started/mix-otp/ets.html
I can't tell you how much frustration I've saved just having reliable mechanisms for timing (thanks pre-emptive scheduling) like `Process.send_after` https://hexdocs.pm/elixir/Process.html#send_after/4
Need to make sure you're only sending messages to live nodes? `pg2` (process groups to the rescue): https://erlang.org/doc/man/pg2.html
Something in Erlang just too slow, write a NIF (but really don't; this (NIF) is a last resort and the only way to you're likely to ever actually crash the VM). You can see a VERY simple example I have in the `wyhash_ex` directory: https://github.com/tehprofessor/shorts (please note shorts is just a toy project, and not quite complete as I got obsessed with the `gen_tcp` part).
Finally, while yes processes, are the fucking peanut butter, jam, and jelly-- you really don't end up using them directly that often in your day to day life. If they aren't making a ton of sense or you don't find yourself using them everywhere, don't sweat it-- when you need to they'll be the obvious solution (even if implementing that solution isn't obvious at first b'cuz learnings).
If you have any Elixir questions, I'm available on Twitter at the same handle as my Github links. Also, the Elixir slack is quite great as well.
[1] LFE is List Flavoured Erlang
Edit: Fixing formatting. God damn I suck at this.
This excerpt caught my attention:
> I've been writing Elixir for like 5-6 years now and four of them professionally, and I hope I never go back to a non FP language (save Rust or mind-boggling pay)
Is there such a big market for Elixir these days? I thought it was very nichey yet.
I think it's been growing pretty steadily, IMHO, because Elixir/Erlang is such a wonderful platform for development, BEAM is extremely battle-tested at this point, and performance is quite good for how easy it all is... also, while I spoke against it, when you absolutely must, to you _can_ write something in C fairly easily (I've _never_ had a good time trying to do C-interop in Ruby or JavaScript for example).
I always wanted to learn it deeply, since I appreciate functional and the concept of Actors, but never thought I would find a job for it easily... I'm changing my mind now.
Thanks for the enlightening!
http://blog.plataformatec.com.br/2020/01/important-informati...
For the Elixir programming language in particular, José Valim and the Elixir Core Team will continue developing and maintaining the programming language in the same capacity as they have been doing over the last few years, independently from Plataformatec and Nubank. We are in touch with the Elixir Core Team to transfer all assets, including the existing trademarks and the Elixir website, to their control.Yeah and that leaves huge chunks like tooling that aren't done or mature. When I walked away from Elixir and Phoenix it was right around when bitwalker abandoned distillery leaving the deployment story unsupported. Blech.
That's why I said the syntax is largely done. They're still actively working on tooling as this release shows. The compiler has some useful improvements. IMHO, a stable syntax leaves more focus on improving the tooling as in this release. It seems to work well for Clojure as well.
> When I walked away from Elixir and Phoenix it was right around when bitwalker abandoned distillery leaving the deployment story unsupported. Blech.
Too bad to hear. Luckily, bitwalker's work has largely been integrated into Elixir in v1.9. So now it will be supported going forward by the core team which makes more sense than one developer supporting a core part of Elixir's tooling.
Recently the Erlang Ecosystem Foundation [EEF](https://erlef.org) was founded and supported by a several companies and the community to ensure the Erlang (including Elixir) ecosystem is maintained.
That pretty well sums up why I rather like Clojure and Rust but not Elixir: tooling is an afterthought, at best, with Elixir.
Luckily, bitwalker's work has largely been integrated into Elixir in v1.9.
That's disappointing to hear. Distillery was a cobbled together mess of bash (not even POSIX!) scripts that should've been put out to pasture ages ago. Elixir has three major problems from my POV: developer tooling is an afterthought, portability is an afterthought, and build artifacts / deployments are unwieldy. Distillery embodies all three and it's a shame that the path forward is simply to throw more bodies at a broken solution.
Recently the Erlang Ecosystem Foundation [EEF](https://erlef.org) was founded and supported by a several companies and the community to ensure the Erlang (including Elixir) ecosystem is maintained.
Unfortunately the status quo is not great – rather than doubling down on poorly thought out solutions it would be nice to see actual improvement. I spent enough time dissecting distillery in an attempt to get deployments to work to make my eyes bleed.
Contrast that with rust where the developer experience is front and center. Even as the syntax evolves over time it remains a pleasure to use. rls is flaky but that's such a minor problem in comparison.
> For the Elixir programming language in particular, José Valim and the Elixir Core Team will continue developing and maintaining the programming language in the same capacity as they have been doing over the last few years, independently from Plataformatec and Nubank. We are in touch with the Elixir Core Team to transfer all assets, including the existing trademarks and the Elixir website, to their control.
Not sure how they are using Elixir, but you can find more about their use of Clojure and Datomic on YouTube. They sponsor/speak at a lot of Clojure conferences.
Sounds like a great business.
Enum.sort(my_list, :asc)
Enum.sort(my_list, :desc)
That rounds off a sharp corner of a very common part of the language.ExUnit is a pleasure to work with and one of the best unit testing frameworks I've ever used.
That's at: https://runninginproduction.com/tags/phoenix
Episodes range from using it in closed source private internal apps in the medical industry to open source apps dealing with billions of events per month on a single server.
Hopefully others will be willing to share more stories in the future. There's a few more episodes going up in the next couple of weeks for Phoenix specifically.
It's hard to imagine working with such a niche language. How easy is it to find quality libraries? Connectors to external systems? Tooling? Someone to ask when running into problems?
Also, what's the market like for Elixir developers? Did you learn the language on the job? For a specific project? In your spare time?
You can usually find high-quality libraries with a google search or looking at the number of stars of a hex package. Mix, the build tool is awesome and the language now has out of the box support for creating deployment releases.
There are a lot of high paying jobs for Elixir.
Libraries are generally of good quality and reasonably well documented. The community is very energetic and supportive. Moreover, there's an exceptional range of libraries and solutions available for certain problem domains in which the Erlang platform excels such as distributed concurrency and soft real-time applications in general.
If the problems you work on fall outside of the web sphere Elixir is not a good fit generally.
I see posts like this https://blog.discordapp.com/scaling-elixir-f9b8e1e7c29b where they are talking millions of events per second.
I also work in the distributed messaging space and so far my experiments have shown elixir to be able to keep up with our scala stack with the advantages of no thread tuning and much easier debugging. So I'm curious why this keeps popping up.
Throughput is always a compromise with latency in garbage collectors and schedulers.
Elixir prioritizes low consistent latency with its garbage collector and preemptive scheduling. Whereas many other systems, such as Haskell's GHC compiler/runtime prioritize high throughput instead for better computational performance.
All the computations have to run inside a process in Elixir. Erlang's platform constrains each process so that any single process cannot hog all the resources available. Therefore, you need to split the computation to many processes when you do CPU intensive work. And processes carry message passing overhead, leading to reduced maximum throughput.
Something like lots of small messages with minimal processing (think: chat) over a bunch of network connections sounds like the ideal sweet spot for Elixir.
Gaming, as far as I know, is not one of them.
I've been able to find high quality Elixir packages without trouble. I haven't had to fall back to Erlang packages for any holes but I feel confident because I could.
Learned on the job, I get a little recruiter email about Elixir specifically but there are definitely less companies that use it. There's reasonable chance I'll end up in Go or Clojure for my next position but even if I were to never use Elixir again the learning will have been worth it.
I moved my last startup to Elixir due to some pretty harsh constraints:
1) I was a the sole developer of a complex app
2) It involved real-time chat and WebRTC
3) Most of its users were in SE Asia and it was a freemium model
This meant I needed a highly productive framework and neither Rails or Laravel were great choices from a technical perspective or in terms of server costs. Phoenix Presence was also a major bonus since there are so many edge cases around (chat room) presence that are easy to mess up when users have multiple devices. That specific need pushed me to learn the language, and it was such a great experience that I made it my go-to for all web development.
> How easy is it to find quality libraries?
I've been very pleased with the quality of the libraries. Elixir tends to draw more experienced developers and I don't see as much "resume-driven Github" behavior, though of course some is inevitable. There's also usually a clear choice of library to use for a given goal, which is a huge plus over the JS ecosystem.
There are a lot of useful libraries out there in the Rails and Laravel ecosystems that I wish existed for Elixir, though. Probably the most frustrating thing on the libraries side is the lack of first-party libraries from companies such as Stripe. Many company's API docs generally assume the user is pulling in their first-party Ruby/PHP/Java/JS/Python/etc library and Elixir usually doesn't make the list.
> Tooling?
The tooling was a big step up from what I was used to! Zero complaints there, except a few minor ones if you're running on Windows.
> Someone to ask when running into problems?
I've had hit and miss experiences with the Slack channel, but the forum is pretty much the best Q/A experience I've ever had for technical issues.
> Also, what's the market like for Elixir developers?
It used to be easy to hire them since there were a lot of people who wanted to use it and not so many companies hiring for it. Now, it seems a bit more balanced.
I love Elixir the language but find myself still having to throughly review new libraries to avoid footguns. In particular with "connectors" -- DB drivers, API clients, basic protocol implementations, etc. And resolving those issues normally means fixing them ourselves, often with a significant refactor to someone else's library. And in turn that's meant some of us having to become fairly proficient with Erlang.
So while I'm optimistic about the future of Elixir there are still some pain points that I think relate directly to the immaturity of the community.
For protocols, we have a not-uncommon use case for which there’s no mature HTTP client. Mint might be an option but it’s new enough that I haven’t evaluated yet.
Also it seems some companies rewrite their Elixir services in Go?
I've been happy with the libraries I've found and used in general. All the common web stuff seems to be there. ExAws solves most of the cloud integration I've dealt with. But I don't imagine I'd find a selection of high-level, highly ergonomic Google Sheets libraries the way you would in Python. Not yet.
I'd say its still early days but healthy for the job market. I've found freelance work with an Elixir shop recently which is fun. But it is nowhere near Python, JS and all. Still, plenty of people making a living as employees or long-term contractors doing it. And it seems to be growing at a steady rate. I'm hopeful.
Learned it out of interest. Tracked down my current client through the Elixir Slack actually.
I'm interested in learning this language but I don't really know what can be built with it ? It is a general purpose language or a more specialised one ?
Thanks for your input
In my case, we use it to power web api, backend systems, databases, IOT devices. Anything that is not a "cli" thing basically. It is not the best for desktop GUI app because it lacks a deep framework for that, but it works well with it if you can make past that hump.
It is not good at: - smartphone app. That is mostly due to the walled garden that these devices are - CLI tools - Systems engineering - on the fly scripting - That basically is it
DIRT (h/t Bryan Cantrill? http://dtrace.org/resources/bmc/DIRT.pdf)
I hope to expand it to other more mundane CRUD-y microservices in the future just for the low maintenance, productivity, easy grokkability it offers.
Are your personal projects web related ? (I'm trying to draw as broad a picture as I possibly can )
On a more advanced level, it also drives websocket communication for our web app, making two-way communication both simple and fast. We also take advantage of its multi-process facilities to drive long running tasks (cron jobs, long-running HTTP requests to slow services, data batching and analysis...) all within the same tool.
It's paid dividends distilling what would otherwise be a complex setup of various tools, each with their own communication interfaces and failure modes, into one simpler system.
Elixir is not "general purpose" like C, Python, or Rust might be, but it doesn't pretend to be. But for writing maintainable, robust, distributed and fault-tolerant systems that do networking, I love it.
But Nerves is a cool project for Elixir + embedded Linux.
Scenic is a neat project for OpenGL UIs in Elixir.
It can do a lot of different things. You can pick it for the concurrency, the durability or the distributed nature of it. Tons of potential applications. So general purpose-ish. But not as general as some others.
Coming from Rails I like that I don't have to go through separate job handlers, everything we need is in the language. I don't like much ecto (too complicated for our need.) I dislike the configuration, build and deployment process (it's definitely not snappy). By the way, it's great that Phoenix autodetects changes and recompiles them without the need of an IDE.
Compared to another Django project I've been working on in parallel, the Elixir one feels more robust and easier to expand upon. Compared to Rails ones, it's about the same but with less third party libraries.
[0]: https://soundcloud.com/elixirtalk/episode-157-feat-chris-mcc...
With docker I imagine we still need the build server, secrets would still be there, compilation must be done there before we create the image (mix phx.server on uncompiled sources is going to take minutes and eat up the CPU of the production server.) Then we must push the image to a registry and pull it. Probably docker would interact better with systemd but I never tested it with a BEAM project. Finally we need something to switch connections from the old container to the new one. Distillery takes care of that now.
All summed up I see some pros a cons, both are still cumbersome. Btw, we're on Elixir 1.7. We didn't check yet the new release and configuration features of 1.9. Too busy with new business features. Customer's decision.
I vaguely remember reading that a release will pre-load all of your modules at boot up time so that by the time the app is running, everything is as optimized as it can be.
But if you use mix without releases then everything is lazily loaded, so unless you had extra code that gets run on deploy to curl all of your endpoints (to warm up the VM) then users would experience slower load times as your app's endpoints were naturally discovered?
It makes me wonder why the creator of Phoenix still decides to not use releases. Unfortunately he didn't go into detail.
I was originally drawn to it because of its superior support for websockets. It can trivially handle shitzillions* of simultaneous connections and thus make fully realtime, dynamic web applications within reach of small teams of developers. Other languages _can_ do this, but with much more complexity and cost to host and develop.
Currently I'm working on a fintech API that doesn't use websockets :). Elixir is a great choice because its syntax is the perfect balance of being expressive but not dense. I find that describing a solution in my head translates almost perfectly to a series of functions. It's my go-to language for any task outside of scripting.
I'd compare the experience of using Elixir to drinking a glass of lemonade on a warm summer day. Everything seems to happen very easily.
* technical term
Now as a team we're developing a more involved application allowing to schedule jobs and services dynamically.
Background processing and real-time updates are among the typical use cases for Elixir/Phoenix.
DateTime.now!/2However sometimes I feel I only use it because of the weird default (non-)handling of timezones by DateTime.
However, since 1.9 it's quite good, IMO. I ripped out Timex from most of the code because it's a beast of a library and not especially well documented, relying on just TzData for the TimeZone database. It's great to rely on just the standard library again because it's up to Elixir's usual standards of documentation and stability.