Live data from Hacker News

Opal: Ruby in Your Browser – the Basics

sitepoint.com

11–20 of 47 posts

Re: Opal: Ruby in Your Browser – the Basics

#11
post #9
post #6

If one needs to write code like: `#{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.

Could you explain what is so offensive about using `...` here?

In 48 lines of code, he has 12 lines where he's evaluating JavaScript between backticks (and not all those 48 lines are significant). If you're having to do that much evaluation of raw JavaScript, then what is the point of using a compile-to-JS language at all?

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).

Re: Opal: Ruby in Your Browser – the Basics

#12
Very cool project. Like others say, it can be a pain to debug generated code in opal, clojure, elixir etc. But that's also true of the code generated by the C compiler. This is a chicken-and-egg thing. Either consumer hardware gets so fast that it's feasible to implement the language vm's in javascript or browsers will support other mechanisms for implementing them. But only when these projects are used by many people, which will happen when the code is easy to debug.

Re: Opal: Ruby in Your Browser – the Basics

#13
How is this "Ruby in Your Browser", per se? You're just saying that you've used Ruby to build a web page now in the browser, correct?

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.

Re: Opal: Ruby in Your Browser – the Basics

#14
post #9

Earlier quoted context omitted.

Could you explain what is so offensive about using `...` here?

In 48 lines of code, he has 12 lines where he's evaluating JavaScript between backticks (and not all those 48 lines are significant). If you're having to do that much evaluation of raw JavaScript, then what is the point of using a compile-to-JS language at all? 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 reme…

I wouldn't mind the outputed javascript - it's unfair to compare it with coffeescript as cs is just a thin syntax layer whereas opal giver you all the goodies of rubyan oop (like, method_missing? :) ), so there is a price that needs to be paid for this. But having to drop to raw js everywhere kind of nulls the advantage. Just think of all the errors that a linter or parser could have caught, but now it can't, and on top of this add it to the inherent pain of debugging a transcompiled language and... not fun :| I liked the idea of ruby to js but this doesn't seem like an acceptable solution.

Re: Opal: Ruby in Your Browser – the Basics

#15
post #2

I'm not terribly convinced by these things that compile to javascript. I don't much care for javascript, but I'd rather take the bull by the horns than deal with a bunch of generated code, especially in any kind of commercial setting where it's going to be a lot easier to hire JS people rather than people who are both X-lang and JS experts. That said, it's very much a cool hack, and worth doing on that basis alone.

How is assembly going for you? What is fundamental to the web is the APIs (dom/websockets/webgl/...) not the fact that they are exposed through javascript. Dart seems especially nice considering that they go out of their way to provide (most?) html5 apis in dart and also Angular.

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)

Re: Opal: Ruby in Your Browser – the Basics

#16
Nice work. I too wish browsers had native support for Ruby.

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?

Re: Opal: Ruby in Your Browser – the Basics

#17
post #6

If one needs to write code like: `#{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.

Yea. They have a canvas wrapper that this guy did not use so you don't have to do that. With that being said, this project https://github.com/rubys/ruby2js is more appealing to me. Sure it doesn't pass more RubySpec tests than Rubinius like Opal does, but it works.

The Angular interoperability is especially appealing to me. It also generates readable javascript.

Re: Opal: Ruby in Your Browser – the Basics

#18
post #2

I'm not terribly convinced by these things that compile to javascript. I don't much care for javascript, but I'd rather take the bull by the horns than deal with a bunch of generated code, especially in any kind of commercial setting where it's going to be a lot easier to hire JS people rather than people who are both X-lang and JS experts. That said, it's very much a cool hack, and worth doing on that basis alone.

How is assembly going for you? What is fundamental to the web is the APIs (dom/websockets/webgl/...) not the fact that they are exposed through javascript. Dart seems especially nice considering that they go out of their way to provide (most?) html5 apis in dart and also Angular. 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)

Javascript isn't really comparable to Assembly though, is it?

Re: Opal: Ruby in Your Browser – the Basics

#20
Why is it so hard for browsers to implement a common set of byte-code. Then we all get what we want and it would make it much simpler to port your favorite language to the browser.

This compile to javascript trend seems so brittle and frail.

Post reply on HN