News for hackers. Stuff that matters.
Re:Elixir v1.3 released by insulanian on Tuesday June 21, 2016 @11:27AM (#11946375)
Anyone here switched from a statically typed functional programming language (Haskel, OCaml, F#, Scala...) to Elixir? How would you describe the experience? What do you miss? What do you like/love? Overall, would you recommend taking that step?
Re:Elixir v1.3 released by alexgaribay on Tuesday June 21, 2016 @12:02PM (#11946700)
I used to do Scala prior to coming to Elixir, mainly by using Play Framework to create web apps. I can tell you that I love Elixir and that I will not be going back to Scala. I miss nothing from Scala.

* Pattern matching in Elixir is superior to Scala's in every way possible (You can pattern match on function parameters!!)

* Async code is a breeze with Task.async()/Task.await() instead of mapping on Future's everywhere and making sure you have the proper implicit globals imported

* Actor pattern is built into the language and it's a breeze to work with. No need to rely on Akka to replicate it

* JSON is a joy to work with

* Documentation is fantastic in the core language and many libraries

* No more JVM!

* Building a release is much easier than dealing with SBT

If you have a functional background, I would recommend reading Elixir in Action as a starting point. It already assumes you have an FP background and takes you into more of the core features of the language. I really enjoyed it and the content is superb.

Re:Elixir v1.3 released by hellofunk on Tuesday June 21, 2016 @12:40PM (#11947042)
> * No more JVM!

You're just trading one VM for another, though. How does having a Beam VM environment differ from a JVM environment?

Re:Elixir v1.3 released by alexgaribay on Tuesday June 21, 2016 @01:05PM (#11947292)
True. That bullet was more of my opinion of disliking the memory usage the JVM uses as well as my personal preference of VM.

BEAM has many great advantages such as fault tolerance and multi-node distribution built in. This allows concurrency to be a first-class citizen for applications running on the BEAM. I'm not saying that concurrency can't be done on the JVM, but that I've found it to be much simpler using BEAM. On the other hand, the JVM excels at computational work compared to the BEAM. Both VMs have their place and can be better at different types of problems comparatively.

Re:Elixir v1.3 released by i336_ on Thursday June 23, 2016 @08:15AM (#11960341)
> [T]he JVM excels at computational work compared to the BEAM.

What sorts of scales are you talking about when you refer to "computational work"?

Also, was/were the comparison(s) you're referring to being done using native code?

Re:Elixir v1.3 released by andy_ppp on Wednesday June 22, 2016 @07:22AM (#11952917)
You can also compile Elixir and Erlang to native code if you want it to run computational stuff faster...
Re:Elixir v1.3 released by ngrilly on Wednesday June 22, 2016 @08:40AM (#11953384)
> You can also compile Elixir and Erlang to native code

How? Can you provide a link about this?

Re:Elixir v1.3 released by andy_ppp on Wednesday June 22, 2016 @09:05AM (#11953542)
Add this at the top of your module (in Elixir):

@compile [:native, {:hipe, [:verbose, :o3]}]

:-o

Re:Elixir v1.3 released by ngrilly on Thursday June 23, 2016 @02:49AM (#11959282)
Hi forgot about HiPE :-)

But it doesn't produce a native binary, does it?

Re:Elixir v1.3 released by andy_ppp on Thursday June 23, 2016 @04:54AM (#11959661)
Where did I claim it did?
Re:Elixir v1.3 released by ngrilly on Thursday June 23, 2016 @05:40AM (#11959794)
Nowhere :-) I read too fast and mistakenly assumed native code = native executable binary.

Is using HiPE a standard practice in the Erlang/Elixir community? What is the quantitative performance gain?

Re:Elixir v1.3 released by lucidstack on Thursday June 23, 2016 @07:52AM (#11960265)
This comment from Reddit sums it up pretty well: https://www.reddit.com/r/elixir/comments/3gd1n3/what_are_the...

I just discovered about HiPE as well, and I just gave it a try with a simple fibonacci module. Running fibonacci(40) went from 3.9s BEAM to 0.7s HiPE.

I know it's a silly test, but it's pretty sweet to witness such a massive difference out of the box. :)

Re:Elixir v1.3 released by ngrilly on Thursday June 23, 2016 @09:06AM (#11960548)
Thanks for the link.

I won't say testing HiPE with fibonacci is silly because this is exactly the kind of numerical computation where we expect HiPE to be useful: it looks like it is :-)

Re:Elixir v1.3 released by tragic on Tuesday June 21, 2016 @01:44PM (#11947706)
To me, there's an interesting point here. Elixir has the advantage of targeting a VM built for a language semantically similar to Elixir; things that have frustrating limitations in JVM functional languages like Scala and Clojure (eg, tail calls) just work on BEAM. Interop, naturally, is also much smoother. Want to call out to some Erlang code? Fine - that'll be ':module_name' instead of 'ModuleName'.

On the other hand, the Java/JVM ecosystem is much larger, so there's a serious trade-off there.

Re:Elixir v1.3 released by asonge on Tuesday June 21, 2016 @03:00PM (#11948424)
There are a bunch of different performance differences, but a couple basic differences: 1) gc is per-process, not global/stop-the-world 2) the VM is responsible for scheduling processes using threads, and can pre-empt...blocking the scheduler is considered a VM bug.
Re:Elixir v1.3 released by phamilton on Tuesday June 21, 2016 @03:14PM (#11948564)
I find failure to be more fatal on the JVM. That's neither a bug nor a feature, it's just what it is.

For example, BEAM puts the process call stack on the heap, so you don't need to tune them separately. You won't hit a stack overflow, you'll just run out of memory.

Many, many characteristics like that exist. I prefer a working slow system over a broken system, but I fully understand the preference for loud failures.

Re:Elixir v1.3 released by perishabledave on Tuesday June 21, 2016 @02:28PM (#11948129)
Having BEAM specifically designed for Erlang concurrency gives it a number of specific benefits. Specifically in how it schedules and handles the VM processes to do efficient concurrency. For example, since the processes are in the VM, it can count the number of function calls to preempt a process that is taking too long.

You can learn more about BEAM here: https://www.youtube.com/watch?v=_Pwlvy3zz9M&feature=youtu.be http://www.erlang-factory.com/upload/presentations/708/Hitch...

Re:Elixir v1.3 released by rdtsc on Tuesday June 21, 2016 @03:24PM (#11948671)
I'll take BEAM over JVM any day.
Re:Elixir v1.3 released by hellofunk on Tuesday June 21, 2016 @03:28PM (#11948694)
Without any reasons for your statement, it's just an empty contribution. Care to explain why?
Re:Elixir v1.3 released by rdtsc on Tuesday June 21, 2016 @03:46PM (#11948864)
Agree, sorry. Sure, here are some randomly ordered reasons:

* Immutable data. This ties into "functional" section below but it is worth mentioning separately. The benefit here is it is a better fit for concurrency and correctness.

* Lightweight processes. Can have millions of them. But they don't share the heap so act like OS processes in that respect. That means 2 things:

1) It changes the way you think and solve concurrent problems. It reduces impedance between real life problems and how they are solved. Spawning a new process for each long lived connection is obvious and easy.

2) Fault tolerance. Having one request not crash the whole server is a really a massive improvement. In C++ or Java you don't know if something got messed up because of a crash. Maybe some shared data structure or lock got left in an inconsistent state. There is just no guarantee.

* Hot code loading. This is not just a gimmick but it works. Most places don't use it to update regularly and I don't either. But used it a few times in production to add extra logging, fix a customer specific issue without shutting down the cluster before the fix was released. All the while there were 100k/sec requests pounding it. That is plain old money in the pocket. No downtime, no headaches.

* Tracing. BEAM has very good tracing support. When debugging I am quite fond of just logging into a node and using tracing instead of print or log statements.

* Functional. This is more about Erlang the language, and it kind of goes with immutable data. But because of that it means state is more visible and explicit. Looking at a piece of code on a page, I get more context of what is happening because State is passed, updated and returned. As opposed to being some "this" reference which at that point in the code, I don't have any idea how it was modified or what it has in it.

* Garbage collection. BEAM has excellent garbage collection. It is pause-less, in the sense that GC of one process won't block the world. Java has lots of tweaks for that but it is not a default state of affairs.

Welp, this is just a quick list off the top of my head.

At the end of the day, one can probably go through the above list and say I can do all that in Assembly or C. Which is true. BEAM is written in C in large part. To get fault tolerance, can just spawn OS processes in any language. To get immutability, can just go to Github and find an immutable collections library for Python or Java. Java can also do some code loading. But the difference is, it all comes in a single package ready to use. That is huge and I see it as a great benefit.

Re:Elixir v1.3 released by acjohnson55 on Tuesday June 21, 2016 @12:52PM (#11947158)
I haven't tried Elixir yet, so I can't really compare on your points, but a couple notes:

You can use https://github.com/scala/async for async/await in Scala. It's super easy.

Also, you can pattern match function parameters in Scal using PartialFunction `case` syntax.

Re:Elixir v1.3 released by methehack on Tuesday June 21, 2016 @12:07PM (#11946735)
There are optional type specs: http://elixir-lang.org/getting-started/typespecs-and-behavio...

which can serve as documentation and are used by a tool called Dialyzer during the build process to find errors based on the type specs.

I have not used this particular tooling first hand, but my sense is that it is well-integrated and works well. Someone else will probably comment with first-hand experience.

The Elixir compiler seems to catch a lot of errors, for what it's worth. If you attempt to call a function that doesn't exist or with the wrong arity, you're going to get an error (even w/o any type specs). The number of compiler errors one has in a statically typed language that are really just about types may not be that many.

w/r/t static vs dynamic, in general, these are the things I'd consider (if you haven't already): you're domain (are you building a rocket or a consumer-facing web app), you're appetite for testing, size of project, size of team, specifics of the tooling w/r/t refactoring (elixir's compiler is pretty good for supporting a big rename, for example; ruby, without a compiler and with so many language features, not so much), how the language makes you feel when you use it (dynamic wins here in general for me; I don't like to be in trouble or interrupted when I'm thinking), the collections library (this is big for me -- I could never go back to a weak collections library -- Go, I'm looking at you), Etc. YMMV, qualifier, qualifier. In general, the specifics really matter -- both of what you're doing and the specific tooling and how they interact.

Elixir seems to strike a very nice balance of all these things with a just right, small, extremely powerful feature set on a rock solid VM with astounding concurrency and distributed computing facilities, if you need them. By all means, I would try it.

Re:Elixir v1.3 released by osense on Tuesday June 21, 2016 @03:58PM (#11948949)
Dialyzer uses something called Success typing. The gist is that while e.g. Haskell won't compile unless it can prove that your code is correct, Dialyzer will only complain if it can prove that your code is wrong.

Personally, when I used Dialyzer in Erlang, I was underwhelmed by the amount of errors Dialyzer caught (type checking concurrent code is hard, who knew?) — however, it is certainly better than nothing. Plus, the type specifications you have to annotate your functions with help with documentation :)

Re:Elixir v1.3 released by shrugger on Tuesday June 21, 2016 @12:16PM (#11946824)
I switched from Ruby to Scala, and I have had an absolute blast. Elixir is sort of chained to BEAM, which doesn't appear to have as bright a future as the JVM or LLVM does, so Scala seemed like a safer bet.

Reading about Elixir is cool sometimes, but then I look at Dotty, and I feel confident that I made the correct choice.

I've also been keeping an eye on Crystal (statically typed Ruby-esque language, LLVM), but they aren't making great PLT choices so far. Maybe they'll get it together later. Scala-Native will blow it out of the water most likely anyways.

Sort of the opposite of losing statically typed programming, but I've really enjoyed the journey and it's improved my work a lot more than I thought it would. I know Ruby pretty well and I used to feel really dumb all the time when things would break, and it took some time for me to realize that it was a language problem. Looking back and reading some of the Ruby that I ported, it was impossible to reason about, and very difficult to make guarantees for. Nothing was solid at all, and runtime errors could hypotehtically stop the show at any time. With Scala there's a much sharper baseline of what will definitely work or not work.

Types make a LOT of things so much easier, in exchange for making a few things SLIGHTLY more tedious. After doing it, I'd make that trade ten more times if I had to.

Re:Elixir v1.3 released by josevalim on Tuesday June 21, 2016 @12:55PM (#11947188)
> Elixir is sort of chained to BEAM, which doesn't appear to have as bright a future as the JVM or LLVM does, so Scala seemed like a safer bet.

Where does this impression come from? The BEAM VM is maintained by Ericsson, we get new "major" releases every year. In the last years we got the maps data type, the new scalable timer API, better tracing facilities, dirty schedulers, and so on. Lately, at ElixirConf Berlin, we heard about the current efforts on scaling the Erlang Distribution to thousands of nodes out of the box (it is already possibly today, just not by default).

They are also plenty of research projects, mostly in Europe, about improving the VM, development experience and scalability in different ways, such as http://release-project.eu/, http://www.prowessproject.eu/ and http://paraphrase-ict.eu/. That's not including the usual suspects like Chalmers and Uppsala in Sweden, which have been exploring different aspects, specially in the testing area with property-based testing, concolic testing, systematic concurrent testing, etc.

Companies like Adapteva (behind Parallella), Basho, Erlang Solutions, Plataformatec, and many more are investing in the ecosystem too. If there is one thing I am not worried about is the VM and the runtime bright future.

In my opinion, the simple fact we have a runtime with preemptive light-weight processes from the ground-up (instead of tackled on top as a library/framework) with per process garbage collection and inter-node communication taken care of is enough to hold the VM for the next handful of years, even if all development ceased today.

Re:Elixir v1.3 released by acangiano on Tuesday June 21, 2016 @01:39PM (#11947647)
I would argue that Elixir's success will further guarantee BEAM's future. (Not that it would die otherwise, but it doesn't hurt.)
Re:Elixir v1.3 released by alehander42 on Tuesday June 21, 2016 @02:11PM (#11947983)
can you give an example of questionable Crystal desicions?
Re:Elixir v1.3 released by mykewould on Tuesday June 21, 2016 @12:48PM (#11947115)
When you say BEAMs future is not as bright, what indicators are pointing you in that direction?
Re:Elixir v1.3 released by ngrilly on Wednesday June 22, 2016 @09:29AM (#11953707)
I can't speak for shrugger, but when I see the manpower invested in improving Java, .Net, JavaScript, Go, LLVM runtimes/compilers, I'm personally wondering if BEAM will be able to follow. We are starting to see languages like Python fade away because of that, when fast execution starts to matter.
Re:Elixir v1.3 released by shrugger on Tuesday June 21, 2016 @12:54PM (#11947175)
Relative to LLVM, I mean. I don't think there are any huge red flags with regards to BEAM.
Re:Elixir v1.3 released by gmfawcett on Tuesday June 21, 2016 @01:43PM (#11947688)
Apples and oranges. LLVM is not a virtual machine, it's a compiler development infrastructure. But JVM vs. BEAM is a sensible VM comparison.
Re:Elixir v1.3 released by smitherfield on Wednesday June 22, 2016 @06:03PM (#11957391)
Doesn't LLVM (or a related project) support JIT compilation?
Re:Elixir v1.3 released by gmfawcett on Monday July 04, 2016 @12:11PM (#12031520)
That's right, LLVM does support JIT compilation. But it's just one tool in the toolbox. I would hazard a guess that most projects which depend on LLVM don't use the JIT compiler.

But even with a JIT compiler, LLVM doesn't provide the kind of runtime services (e.g., memory and resource management) that we would typically associate with a VM runtime like the JVM's. Like their Web site says, "Despite its name, LLVM has little to do with traditional virtual machines, though it does provide helpful libraries that can be used to build them."

Re:Elixir v1.3 released by shrugger on Tuesday June 21, 2016 @03:39PM (#11948805)
Note the lack of technical claims that one is superior to the other, thanks for pigeonholing what I was getting at.
Re:Elixir v1.3 released by iends on Wednesday June 22, 2016 @11:13AM (#11954551)
I don't think you've communicated what you were trying to accomplish very well with your LLVM comparison. Many people will see it and think you're confused at what you're talking about.
Re:Elixir v1.3 released by rdtsc on Tuesday June 21, 2016 @03:26PM (#11948684)
> Scala

That means being chained to JVM. That is a big downside for me.

Re:Elixir v1.3 released by shrugger on Tuesday June 21, 2016 @03:38PM (#11948795)
Or JS with Scala.js Or literally anything with Scala Native, which is being sponsored and supported by EPFL directly.

So yeah, no.

Re:Elixir v1.3 released by rdtsc on Tuesday June 21, 2016 @04:05PM (#11948994)
I saw about 5-6 products which use Scala.js and I haven't heard of any of them before. Who else uses that? Seems rather obscure.

Is Scala Native used widely? They just finished implementing java.lang.String 20 days ago or so. At least Erlang on Xen has been serving web pages for a few years now: http://erlangonxen.org

But most usage of Scala is on JVM still, wouldn't you agree? We are not talking CPython/Jython/PyPy/Numba... I don't know, the claim that Scala is widely implemented on other platforms while Elixir is tied to BEAM doesn't quite go far for me.

Re:Elixir v1.3 released by shrugger on Wednesday June 22, 2016 @02:42PM (#11956045)
I understand, but your opinion doesn't change the facts. Scala.js is more than mature, with some huge projects already built in it. I'd not heard of erlangonxen, but it would take a lot of convincing to re-write something in Erlang to begin with, when I could write it quicker in Scala, and run on 2, eventually 3 different platforms.

Scala Native is not very far along compared to Scala.js, but it is actively being improved, and is considered an official extension. Additionally, Dotty will bring huge improvements for JVM scala.

I am not super happy with JVM most days, but I'd far and away prefer to be chained to JVM than BEAM. I mean, it's not even a question at this point, considering the billions of dollars spent developing JVM and the work of the brightest minds of several generations. Joe is a cool guy and all, but Erlang is objectively a niche platform compared to JVM.