Opal: Ruby in Your Browser – the Basics
sitepoint.com
sitepoint.com
That said, it's very much a cool hack, and worth doing on that basis alone.
Unfortunately I think JS is having a lot of responsibility heaped on its slightly creaky shoulders these days, due to the growth in mobile intarwebsing and every man and his dog looking for a quick way to build the app that is going to bring them fame and fortune. As a result of this, we're seeing a lot of these frameworks which compile [arguably!] 'better' fuller-featured languages down into JS.
Personally I'd rather a scenario where people could code in <insert language of choice> and embed this in HTML as easily and ubiquitously as JS can be embedded. A bit of a pipe-dream I know, but wouldn't it be great if we could exploit the cross-platform accessibility of web apps, without having to turn everyone into a Javascript hacker?
That would indeed be amazing. Anyone want to build it? :P
In fact the dom is defined in an IDL which can generate the dom API not only in javascript but a lot of other languages (Java/C++/etc)
This is an argument that tries to emotionally justify the limitations of web browsers that force us to compile down alternative languages into web "assembly".
`#{context}.lineTo(#{x}, #{height})`
...you're doing it wrong. Please do figure out a way to "automagically" make things work without `...` or just don't bother.`...` should be a last resort option for when you just need to do something that can't be done any other way, not something that should be peppered over the entire code.
The author used a lot of JavaScript here, likely for teaching purposes, but he could instead have used pure Ruby to interface with canvas using opal-browser. https://github.com/opal/opal-browser/blob/master/opal/browse...
The Angular interoperability is especially appealing to me. It also generates readable javascript.
On the other hand, being able to drop down to native javascript anytime you like is a huge win.
With CoffeeScript, I think I've "had" to use backticks all of about twice (I probably didn't actually have to, but it seemed easier at the time - I don't remember the exact circumstances).
Also, as others have said, the JavaScript that this outputs is a real mess (in comparison with, say, CoffeeScript).
This compile to javascript trend seems so brittle and frail.
Google and Mozilla are the only mainstream browser vendors that have an incentive to offer a bytecode alternative to the JavaScript status quo, whereas Apple and Microsoft would simply be undermining their respective platform positions.
This means that Mozilla could have worked with Google to form a bloc; Chrome and Firefox would have been the only browsers to support better web technology, and that might have been enough to force Microsoft and Apple's hand.
Instead, Eich stuck to his "JavaScript First" guns for years, wasting market opportunities and in the process, serving as the swing vote that held the entire web back.
I hope that the next CEO of Mozilla realizes that for platforms like Firefox OS to have a snowball's chance in hell, they need to work with Google to move past HTML/CSS/JS.
Part of the problem is that Webkit has a very narrow mission of wanting to only be standards compliant. This is really holding back innovation given how widely used it is in Safari and until recently Chrome.
It seems to me that in order to make it happen, it would need wide support from one of the major browser vendors.
- The only number representation available is floating point.
- Concurrency is impossible except for the nearly useless web workers API; this prevents a language author from exposing any other type of concurrency mechanism.
- Anyone wishing to implement the "byte code" specification must implement or integrate a full Javascript parser and runtime.
I ask because I'm seeking something more like a Ruby on Rails Implementation waiting for you in your browser, in effect, when you arrive at the service's website, which you can then take with you if you'd like, as a VM, in any number of ways.
The maker of `lissio` also started hacking on a little project that is not complete, but gives an idea of a WIP lissio project here: https://github.com/meh/gwentoo
Just kinda nice to see how it goes together and how very flexible it is.
Like have others have said, I'm really turned off by the `...` js evaluations all over the code. I wonder why that opal-jquery gem doesn't have cleaner ways for interacting with the DOM. Is that the only way you can do it?
About the raw JS, to use my current app as an example, I have one line of inline JS (using `...` notation) which is just to initialize FastClick. Writing a ruby wrapper wasn't worth it for one method call. Anytime I see more then 1 line of inline JS inside a file, a ruby wrapper ends up being a much better idea, or indeed using the `Native` class which handles all the corner issues of calling native JS libs.
I think the problem with Opal is the documentation, which needs huge improvements, to show the proper/realistic development experience with it.