Skip to content

Instantly share code, notes, and snippets.

@elia

elia/a.md Secret

Created June 9, 2014 13:52
Show Gist options
  • Save elia/1a42ac9381bd8a97ad71 to your computer and use it in GitHub Desktop.
Save elia/1a42ac9381bd8a97ad71 to your computer and use it in GitHub Desktop.

If you've got a way to compile Ruby to JS that has tolerable arithmetic perf and doesn't do type analysis or generate a huge volume of code, I would definitely like to know more about it.

Yeah, that's kinda the point, you can do that and preserve Ruby semantics?

Let me note here that is a strawman indeed, Dart has frozen classes, Ruby is a bit different. In order to do something like that you should inline a ton of ternary operator to check if the method has been redefined on that particular object.

Something like:

(a._isNumber && !a._plusRedefined) ? a + 1 : a['$+'](1)

plus listening on new method definitions to set _plusRedefined.

It's definitively a trade off, readability will suffer.

Opal had optimized operators in the past (that assumed native operations on numbers), they could even be back in the near future. But what I see here is a comparison of two different language semantics. I agree that “compiling to JS is hard”, but I don't think that this demonstrates anything. What can be argued instead is that JS VMs could and should do that for us.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment