In all my thinking about the Elixir ecosystem all I can do is keep comparing it to Java because in my mind the BEAM is analogous to the JVM (but takes an approach that suits my brain better). I’m wondering if there are other well known virtual machines that I can compare and contrast the BEAM with.
Perl/Python/Ruby all compile down to byte code. In the case of python, the byte code can be serialized out as .pyc file. In the case of Perl and Ruby the compiled byte code exists only in memory because they do not want to commit to a stable ABI.
Javascript in either browser and node.js are compiled down to byte code prior to execution; not unlike perl or ruby.
On the other hand, Rust and Go use LLVM to compile down to native code prior to execution. I don’t think it is me, but a generally accepted classification of language environments:
Most interpreted languages, except shells, run on some sort of VMs.
Thanks for a good explanation. I suppose one can expect Python or Ruby code that runs on a MacBook to also run on a Windows machine, so in that sense they are hardware-independent and run in a virtual machine. I’m not sure that the abstraction away from the underlying machine is all that powerful when in comes to Ruby/Perl/Python, though. The JVM and the BEAM seem like they are virtual machines for applications, while Ruby/Perl/Python interpreters seem like they are virtual machines for scripts.
Another observation I have is that when I am thinking about the BEAM I find myself thinking about “programming a computer”. When I think about the JVM I think about “using an interface to program a computer”.
The BEAM feels like putting my whole arm up inside a puppet, whereas the JVM feels like trying to control a puppet via some strings attached to a stick.
I think that the reason the BEAM feels directly like a computer to me whereas the JVM feels like only an interface to a computer is that the BEAM allows me to reason about processes and threads of execution in a clearer and more powerful way.
There is also a sense in which I think of the BEAM as being “turned on”, sort of like a computer might be turned on or a car might be idling in the driveway. The environments for Python/Ruby/Perl never feel like this to me.
Wow, interesting – I wonder if I can find a hardware JVM on eBay. It might be a nice way to acquire a JVM and then videotape myself beating it to death with a hammer.
HipHop Virtual Machine, formerly for PHP, now for Hack, was a big thing in the PHP circles earlier. It made PHP devs push for more performance in PHP 7.
Surprised no one has mentioned the one lurking in millions of pockets all over the world: the Android Runtime (ART): Android Runtime - Wikipedia.
I would love to see a cross-compiler to translate BEAM files into .dex but I’m sure there are lots of technical hurdles to that. But as an Elixir lover who has suffered through trying to get somewhere with building a mobile app using React Native, being able to write at least an Android app in Elixir would be awesome.
The Warren Abstract Machine is the de facto standard target abstract machine which Prolog-implementations target.
The family of Forths (and threaded interpretive languages in general) also target a very interesting minimal stack-based machine. It’s probably as close as you can get to a minimal virtual machine which still is practical: Bootstrapping Forth on a new target platform takes no more than a weekend.
There are also a couple of FPGAs which can execute Forth-code directly.
Ah, forth, quintessential VM for sure. Thanks for the reminder! Still prefer my old HP 12c over any other calculator in part because of stacks, RPN and forth.
Only one correction: Perl doesn’t compile to bytecode, it compiles to AST (abstract syntax trees). Python, Elixir (and other BEAM vm based languages), Javascript, JVM based languages, .NET based languages, they all compile to bytecode.
In Ruby it depends. Erruby (ruby on BEAM), JRuby and Rubinius compile to bytecode. MRI (cruby) and mruby compile to AST. TruffleRuby compiles to native executable code.