Opal looks like nice library, but I'm not sure if there is real use for it. How do you use it? Or is it just a curiosity?
-
2Theoretically it allows the entire ruby team to work on the frontend without need to learn JS. IMO, just learn javascript - it is quite simple with just few major weirdness, and learning new language pretty much always improves ones general, transferable programming skills. But this will be too much opinion-based for the wider discussion on this site, which is designed for concrete problem solving. – BroiSatse Feb 20 '21 at 10:41
1 Answers
Ruby is a programming language. A programming language is a set of abstract mathematical rules and restrictions. It is an idea, a specification, a piece of paper.
You can write programs in a programming language, but if all you have is the programming language itself, then all you can do with those programs is read them, study them, prove properties about them, etc. But you cannot run them (other than in your head or using pen and paper).
That does not make the programming language useless, however. There are plenty of programming languages that were never implemented, they were only created in order to write programs and prove properties about those programs, or study properties of the programming language itself.
Ruby, however, is intended as a practical programming language. Programs written in Ruby are meant to be executed, and not with pen and paper.
Which means we need another piece of the puzzle, we need what is called a programming language implementation.
A programming language implementation is itself a program written in some programming language (it could be the same one or a different one) that "understands" programs written in the programming language and does one of two things with them:
It "runs" them, meaning it performs the side-effects and operations of the program according to the specification of the programming language. This kind of implementation is called an interpreter.
It "translates" them into a different programming language, i.e. it translates a program written in the source programming language into a semantically equivalent program in the target programming language such that interpreting the resulting output program with an interpreter for the output programming language yields the same results and performs the same side-effects as interpreting the source input program with an interpreter for the input programming language.
Ruby actually has quite a number of programming language implementations:
- YARV
- MRuby
- TruffleRuby
- JRuby
- Rubinius
- Artichoke (still in development)
- Ruby+OMR (not sure whether this is still developed)
- IronRuby (no longer actively developed)
Opal is simply yet another programming language implementation of Ruby. In that regard, it is no different from any of the others. All of them have their strengths, their weaknesses, their use cases, their niches.
Opal is somewhat unique compared to the other ones in the list, in that it is a pure compiler. XRuby and Ruby.NET work the same way, but those are no longer being developed. All of the other ones in the above list use an interpreter for at least some code some of the time in some form. For example, while YARV never interprets Ruby, it always compiles Ruby to YARV byte code, it typically interprets that YARV byte code at least a couple of times before handing it off to the JIT compiler.
So, the reason to use Opal is the same reason to use any of the other Ruby implementations: you have a Ruby program and you want to run it. And in order to run it, you need a Ruby implementation.

- 363,080
- 75
- 446
- 653