Live data from Hacker News

Opal: Ruby to JavaScript Compiler

opalrb.org

31–40 of 69 posts

Re: Opal: Ruby to JavaScript Compiler

#31
post #13

afaik,it's not really a ruby to javascript compiler(like coffeescript compiles down to js). You cant write xhr = XMLHttpRequest.new and expect it to compile in js.without importing some libs.

It is really a ruby to JS compiler. Ruby, however, is not just a thin layer over JS the way CoffeeScript is. The thing you are referring to is a sign of CoffeeScript being a thin layer over JS, not CoffeeScript's compiler being a "real compiler".

my point was it doesnt transpile Ruby to Javascript.

Re: Opal: Ruby to JavaScript Compiler

#35

Earlier quoted context omitted.

Ruby and JS are both Turing-complete languages (as with just about any other programming language you'll ever use), which means that one can simulate the other. The simulation might be messy, complicated, or slow, but it will still work. In this case, Ruby and JS are close enough that it can be done without too much trouble (see the compiled JS).

But does "anything written in language A can be simulated using language B" imply "A can compile down to B"?

yes. If you can write a body of code X in language B which performs the same operations as any given body of code Y in language A, then all an A->B compiler needs to do is find X given Y.

Re: Opal: Ruby to JavaScript Compiler

#36

Earlier quoted context omitted.

Ruby and JS are both Turing-complete languages (as with just about any other programming language you'll ever use), which means that one can simulate the other. The simulation might be messy, complicated, or slow, but it will still work. In this case, Ruby and JS are close enough that it can be done without too much trouble (see the compiled JS).

But does "anything written in language A can be simulated using language B" imply "A can compile down to B"?

Yes, it does. It may not be easy, efficient, or elegant, but theoretically any problem solvable by a turing complete language can also be solved by any other turing complete language.

Re: Opal: Ruby to JavaScript Compiler

#37
post #24

How do people know that one lang would compile down to another? Is there something about the lang that make this possible? Also, is it possible that something won't translate from ruby --> js and cause a bug?

If there is a bug in the compiler, is possible that something won't translate ruby --> js and either:

* throw some error from the compiler.

* cause a bug in the resulting code.

Re: Opal: Ruby to JavaScript Compiler

#39
Since the Opal developers are reading:

I'm curious, do you plan to support Encodings and proper Ruby strings, or it isn't worth the effort, and you'll keep using plain javascript strings?

(I tried to look for this detail on the website but came back empty-handed)

Re: Opal: Ruby to JavaScript Compiler

#40

Earlier quoted context omitted.

As DouweM said; there is a case to be made for having the whole stack in a single language. While I use different languages server side, Ruby (either with Rails or Sinatra) is my go to option more often than not these days. I have used CoffeeScript extensively, but this has always been on contracts where the decision was made by someone else. It is important to learn and use real JavaScript (IMHO) rather than all of…

>I have used CoffeeScript extensively, but this has always been on contracts where the decision was made by someone else. >It is important to learn and use real JavaScript (IMHO) rather than all of these transpiled languages. This is the route I take when I have a choice on the client side; I use JavaScript. I've been using Rails and Coffeescript. Intuitively, I feel like using Javascript directly would be better som…

If you don't know JS really well, I wouldn't recommend Coffeescript. It's hard to tell what will work correctly and what won't unless you're quite familiar with the actual code the Coffeescript is compiling down to. I don't know how true this is for other transpiling languages, but it's definitely true for Coffeescript.

I'm a pretty experienced JS dev, so I know exactly what my CS is compiling to and what that's going to do. If I didn't, CS would make me tear my hair out within a week. As it is, it's just shorthand for JS with a bunch of quality of life improvements (?, no var, etc).

Post reply on HN