Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Elixir Design Goals (2013) (elixir-lang.org)
191 points by qubitcoder on Dec 23, 2016 | hide | past | favorite | 38 comments


Once you scratch the surface and get to the functional core, you will never want to go back to object-oriented programming. Maybe it's just me, but since I have tried functional programming, I have never felt the need to go back to OO. Can't say the same about OO, whenever I'm doing it, I kind of tend to design my code as functional as possible.

Elixir has it all (well, almost). It's fast, it's compiled AND interpreted, it has a REPL, it has strong concurrency, reliability and scability backed into the VM. It has a simple and beautiful syntax. It has great tooling and is very well documented. The only thing you might miss is static typing.

I've been looking for my next programming language of choice after Ruby for almost 2 years now. Clojure was the closest I got to replacing Ruby, but now with Elixir it's just such an obvious choice.

If you haven't tried Elixir yet, PLEASE go and do it right now, you won't ever regret it.


Is Erlang Object-Oriented?

https://www.infoq.com/interviews/johnson-armstrong-oop

Then, my thesis supervisor said "But you're wrong, Erlang is extremely object oriented". He said object oriented languages aren't object oriented. I might think, though I'm not quite sure if I believe this or not, but Erlang might be the only object oriented language because the 3 tenets of object oriented programming are that it's based on message passing, that you have isolation between objects and have polymorphism.

Though I must said I am pretty happy with CLOS (Common Lisp Object System), in particular its generic functions.


> Elixir has it all (well, almost). It's fast, it's [...]

Dude, Elixir compiles to BEAM, it's slow as hell. Have you ever compared its processing speed with virtually anything else? It's not processing speed that Erlang is sold about.


> slow as hell

A bit of an exaggeration. It's not as fast at math as Java. It's quite faster than Ruby (while keeping coder-friendly features such as auto-rollup to bignums). If you use pattern-matching correctly, it is EXTREMELY fast at I/O or binary parsing. That puts it in a unique space of "people who don't want to sit on the JVM yet want a fully-functional language that has an accessible syntax AND macros AND massive concurrency"... Web developers, basically.

Let's see your favorite "faster" language do THIS: https://discord.engineering/how-discord-handles-push-request...

My experience with Clojure ended when I got a blown-up gross Java stack trace because I went out of bounds on the underlying Java int representation. Fuck that, I consider that "janitorial duties" and not something I should be responsible for as a programmer. YMMV. No offense to you C guys. ;)

http://adrian-philipp.com/post/why-elixir-has-great-potentia... Check out the chart: https://cloud.githubusercontent.com/assets/133832/21369162/f...

You know how "simpler is better" from a maintenance standpoint? Elixir has that in spades.


>> slow as hell

> A bit of an exaggeration.

Actually, no. Last time I compared BEAM (Erlang) and something else, Erlang code that only parsed text data from a file (CSV) was several times slower than Perl script that parsed that, built a structure, serialized it, and wrote back to a disk file (BerkeleyDB).

> It's quite faster than Ruby (while keeping coder-friendly features such as auto-rollup to bignums).

I doubt it, unless Ruby (MRI is what I think of) is an extremely poorly written interpreter.

> If you use pattern-matching correctly, it is EXTREMELY fast at I/O or binary parsing.

It's not. It's slow (I've seen it when comparing with other runtimes). It was never intended to be fast. It was always intended to be convenient and highly concurrent.


> Actually, no. Last time I compared BEAM (Erlang) and something else, Erlang code that only parsed text data from a file (CSV) was several times slower than Perl script that parsed that, built a structure, serialized it, and wrote back to a disk file (BerkeleyDB).

Yeah, Erlang/Elixir are both not very fast when it comes to stuff like file parsing. Jose, the creator of Elixir pointed that out several times before. But as mentioned before, web developers can greatly benefit from Elixir.

> I doubt it, unless Ruby (MRI is what I think of) is an extremely poorly written interpreter.

I wrote several things in both languages. CSV parsing is pretty much the same speed, again file handling in Erlang/Elixir. When it comes to real web apps, Elixir is usually faster by a factor of 10x when DBs are involved and 100x when it comes to plain rendering.

> It's not. It's slow (I've seen it when comparing with other runtimes). It was never intended to be fast. It was always intended to be convenient and highly concurrent.

As others have mentioned, depends on what you think is fast and in what areas. When it comes to web apps, Elixir is way faster than ruby, python and even node. Pattern matching, for instance used for router matching is very fast compared to the techniques used in ruby/python frameworks.

Java, Go and several other languages are faster as Erlang/Elixir, of course. But Go is too low level for huge apps and Java is a whole different beast. Basically, Elixir is a nice middle ground to develop fast-enough web apps with high concurrency and easy scalability without sacrificing dev speed and dev fun.


> But as mentioned before, web developers can greatly benefit from Elixir.

I'm not saying they wouldn't. I just object against calling Elixir "fast", because it's not. It's just used in the places where raw sequential processing speed is not what makes the difference. It only makes up for that loss because it doesn't degrade when the same procedure is executed many times simultaneously, which is very hard for anything that's not BEAM (or Go, so I hear).

>> I doubt it, unless Ruby (MRI is what I think of) is an extremely poorly written interpreter.

> I wrote several things in both languages. CSV parsing is pretty much the same speed, again file handling in Erlang/Elixir.

Funny. I expected MRI to be as fast as Perl or Python. What you say means it's much slower.

> When it comes to real web apps, Elixir is usually faster by a factor of 10x when DBs are involved and 100x when it comes to plain rendering.

Unless I see how the comparison was arranged, I have trouble to believe that. I've seen BEAM being very slow for sequential workload, and there's no mechanism that would explain the speedup right off the bat, barring the possibility of comparison looking at apples and oranges (e.g. comparing raw SQL queries in Elixir to Django's ORM).


What's/where's your evidence?

1) The situation might have changed since you looked at this

2) The algorithm to do the work might have been suboptimal (for example, not taking advantage of pattern-matching, or using regex which everyone agrees is too slow in Erlang/Elixir)

3) for large files, there's some fiddly techniques that make things noticeably faster, see for example http://cloudless.studio/articles/12-elixir-vs-ruby-file-i-o-...


1) It might, but I doubt BEAM got rewritten in that extent.

2) Split on a comma is very hard to get suboptimal, especially when it was `string' module supplied by Erlang.

3) Half of those fiddly techniques will be very, very hard to use in Erlang (I understand that the thread is about Elixir, so you sort of assumed that I was talking about it even though I explicitly said that it was Erlang and BEAM code). Then, the load was on the CPU, not I/O. Reading the file upfront was not going to help.


I don't know why you're getting downvoted just for dissenting. I don't want HN to be another damn Reddit echo chamber. Lots of criticisms of popular things are valid. I thought we were just having a civil discussion, but now I'm angry BECAUSE you got downvoted lol

But I would still like to see any evidence from you if you'd like


This was a great article on this sort of thing http://cloudless.studio/articles/12-elixir-vs-ruby-file-i-o-...

Tl;dr: Elixir is a bit faster than Ruby for straight up File IO if you really know what you're doing. Naive approaches in Elixir can lead to terrible performance.

I'm a huge fan of Elixir, but eeking out better performance can require some tricks that aren't intuitive if you're new to the language.

From personal experience (we're using Elixir at work) and we compared parsing a CSV in Elixir vs Scala, and the Elixir version was about 20% slower. However, for our use cases, we can more than make up for it by parellelizing processing downstream, ie: the csv parsing wasn't going to be the bottleneck anyway - other things, (which are easily parallelizable if you're running on BEAM) are the bottleneck, so BEAM gives us some nice things the JVM doesn't.


This discussion is going in circles.

Fast at what?

From what I read, Elixir is very fast at I/O based tasks, especially when there is lots of blocking involved. For example orchestration layers that push data between various API's and/or handle many concurrent connections.

Languages that compile to the JVM like Scala or Clojure (or Java of course) will probably be faster for computation.

I see Elixir as being suitable for the same category of applications as nodejs.


> I see Elixir as being suitable for the same category of applications as nodejs

While being a hell of a lot saner.

https://www.quora.com/How-is-Elixir-Phoenix-better-than-Node...


> From what I read, Elixir is very fast at I/O based tasks, especially when there is lots of blocking involved.

Now make two steps back and read this again. What you say is that Elixir is "very fast" when it comes to tasks when Elixir pretty much doesn't do anything, so it being fast or slow doesn't matter. Hardly a definition of "fast".

But it is actually true for BEAM machine. It was never intended to be fast, it was intended for running many tasks at the same time (so that none of them starves others for any reason).


Slow as hell is a very scientific measurement :) Processing speed for what workload on what hardware? You do realise there are a lot of workloads that need to be optimised for latency? If we take web dev. Phoenix based solutions are about on par with one's based on a typical Go framework like Gin and are significantly faster than something using PHP, Ruby, Node, Python based web frameworks for a real world workload.


> Slow as hell is a very scientific measurement :)

On par with the claim that "Elixir is fast".

> Processing speed for what workload on what hardware?

Sequential processing, what did you think? BEAM excels at running many sequential processes at the same time, it would be very hard to match that. (And that's why for text processing I use Perl or sometimes Python, but for services that pass data back and forth through network I use Erlang.)


How would you compare elixir against clojure ?


They are functional to the core, but pragmatic. They allow you to get stuff done, while focusing on data instead of state of class hierarchies.

Clojure runs on the JVM and interops with Java, which can be both an advantage or drawback, depending on who you ask. Personally, I don't enjoy working with the JVM too much, but people who are already using a Java / JVM stack can easily switch to Clojure while still being able to use all their libraries. Elixir runs on top of the Erlang VM which at least feels a lot more lightweight than the JVM, and has a strong focus on distributed, concurrent and fault-tolerant systems. Also, you can interop with Erlang, so you have access to many mature libraries, same as Clojure has on the JVM.

Both Clojure and Elixir focus on concurrency and bring first-class support out-of-the-box.

Clojure is a Lisp, which in terms of syntax is usually controversial. I personally love it, but a lot of people are overwhelmed by too many parentheses, and I kind of understand them. Elixir has a pretty polished, easy on the eye syntax. Of course, coming from Ruby, I might be a bit biased, would love to hear what people with other backgrounds think about it though.

One negative point about Clojure is that it's difficult to have a really smooth and quick development environment, and debugging Clojure can be a tough task, as it basically dumps tons and tons of Java stacktraces that are very difficult to process. Here, Elixir clearly wins, as it has one of the best and most accurate stacktraces and error messages I've seen in a programming language.

In the end, I think both are just terrific programming languages and have their own reasons to be. I'd actually love to work someday at a company where people would use Clojure, Elixir and many other functional programming languages, depending on the task at hand and the requirements :)


From an Erlang/OTP vantage point, what Elixir ended up being famed for is its relatively good tooling.


There is a fantastic talk by Fred Herbert (of Heroku and Learn You Some Erlang fame) that discusses this exact situation in the Erlang community [0]. Without an accessible ecosystem, useful tooling, a powerful packaging system, or a community sensitive to newcomers what do you have? Erlang is an amazing platform with a community full of very experienced and wisened developers–but elixir widened the appeal.

[0] https://m.youtube.com/watch?v=Z28SDd9bXcE


That's what initially attracted me to Elixir instead of Erlang, though the tooling has definitely improved in Erlang with the introduction of rebar3. The integration of testing and documentation (i.e. doctests) is still better than any other language I've worked with. The documentation generator (ex_doc) is excellent too.


That's interesting, why?


Because Elixir is a modern programming language that ships with out-of-the box tooling for dependency management, project management, deployment, and so on. This is something to be observed in any relatively new programming language: Elixir, Rust, Go, Swift. They all ship with solid tooling that allows programmers to be more productive from the very beginning without having to figure out the whole build chain themselves.


Elixir is pretty O.K., I use it at work and the restrictions typically have me writing cleaner code.


In my experience Elixir's pattern matching in particular leans to very clean looking code. Type checking sort of conditionals that would be 3 lines in JavaScript are just enforced in the arguments in Elixir for example.


The restrictions are what I really appreciate about functional programming, and why I find slapping FP features on top of OO or imperative languages not particularly compelling.


Hmmm, the tutorial seems to suggest its strings are linked lists of characters. Is that true?


You have two -- charlists like you're describing, which are just linked lists of characters under the hood and UTF-8 binaries. Charlists are denoted with single quotes and the UTF-8 ones are denoted with double quotes. Truthfully, I reach for the UTF-8 ones most of the time, but you can get some good performance gains in e.g. template string building in web frameworks if you use charlists. In Erlang, all the strings work like charlists FWIU, so they need to exist at least in some capacity for interop reasons.

http://elixir-lang.org/getting-started/binaries-strings-and-...


Are you thinking of IO lists[0] when you talk about templates with respect to web frameworks?

[0] https://www.bignerdranch.com/blog/elixir-and-io-lists-part-2...


I totally am and now I look silly :) Good catch.


Not at all :) If you haven't read that post by bignerdranch, i'd definitely recommend it. It was interesting read (both parts 1 and 2)


If you want them to be, yes.

Erlang's normal "string" type is indeed a list of integers representing codepoints. Erlang also supports "bitstrings" or "binary strings", which are basically what most other languages would just call "strings", as a logical extension of its existing binary data syntax.

Elixir instead uses Erlang "bitstrings" as its default "string" type. Erlang integer-list-based "strings" are represented in Elixir by using single-quotes instead of double-quotes around such a string (or by just manipulating a list directly; Elixir will transparently convert a list of integers into an Erlang-style charlist if the integers are valid codepoints).


Linked list strings are not necessarily terrible in a language with immutable data like Elixir.


those exist for compatibility with Erlang. Elixir strings are UTF-8 encoded binaries.


erlang 'strings' are utf-8 encoded binaries also, they just have slightly terrible syntax


This is incorrect. In erlang the binary type is like a blob or byte array. Strings are linked lists of individual code points. Elixir encodes strings in erlang binaries.


Not the lists of integers that happen to be characters.


I just wonder what's it's design goals in the future. I noticed that Elixir team seems working hard on something like GenStage and so on.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: