Monday, November 10th, 2008

Redshift: What Ruby and a nice API can do in the browser

Category: Rails, Ruby

<>blockquote>

Red writes like Ruby and runs like JavaScript

That is the tagline for Red, and they mean it:

The all-new Red is a Ruby-to-JavaScript transliterator backed by a custom ruby.js library designed to let your code run in the browser exactly* the way Ruby would run on your machine. The JavaScript output is optimized to contain only the fraction of the ruby.js source library needed to run your code.

What does this mean for today’s Ruby developer? Simple. You don’t need to learn JavaScript.

Trek Glowacki shows us what this is all about. When I wrote about running JRuby in the browser I talked about the desire for a nice API to the browser side of things. Having Ruby is fine and all, but what about the APIs? What about the standard library?

In the demo screencast below you get to see some of the APIs in question, such as:

  1. Document.ready? do
  2.   Document['.photo_wrapper'].each do |el|
  3.     PhotoBucket.new(el)
  4.   end
  5. end

Related Content:

Posted by Dion Almaer at 8:08 am
16 Comments

++++-
4.5 rating from 21 votes

16 Comments »

Comments feed TrackBack URI

Just pray you don’t have to debug someone else’s work, you’ll be ass deep in both JavaScript and Ruby. I like the concept though, too bad the video is such low quality. I can’t see what’s going on too well.

Comment by TNO — November 10, 2008

TNO – the source video is in HD. Head to vimeo and you can watch it full screen in HD streaming or download the source .mov file.

Comment by trek — November 10, 2008

It would be breath taking to step into the minds of the average Ruby developer. Tell me, what is it about Javascript that causes your tails to fall between your legs? This is yet another attempt by your average narrow minded Ruby novice who wished Ruby was the only thing we should have to know. WAKE UP !

I have just finied up a 6 month Rails project at a client where RJS was seriously enforced because javascript “was so terrible”. It’s ironic that Ruby programmers promote beautiful clean code, yet don’t see that their partials/templates turn into a hog mess of sloppy helper/rjs methods.

Do you want to solve a real problem? Figure out how to bridge client server ajax apps, not hide such an amazing language because you guys just cant do it.

Comment by jaysmith — November 10, 2008

Where is the link?

Comment by henrah — November 10, 2008

hmmm……trek makes a good point.

Comment by ech0base — November 10, 2008

I have to agree with trek as well on this, I have yet to be given a valid reason to stop using JavaScript, especially given the proliferation of libraries (prototype, jQuery, YUI etc) and improvements in tools (ie. Aptana Studio)

Comment by ryanmcilmoyl — November 10, 2008

The browser is running JavaScript. For me to debug the final output, I need to be in Firebug looking at JavaScript. As long as that’s the case, I sure don’t want to lose my JavaScript chops.

If the browser in the future becomes language-agnostic, that situation may change.

Comment by Nosredna — November 10, 2008

“What does this mean for today’s Ruby developer? Simple. You don’t need to learn JavaScript.”

Heaven forbid a dev should learn another language.

Comment by horia314 — November 10, 2008

Not sure how everyone’s off-by-one error occurred but the comment you’re all agreeing with is by “jaysmith” not be me. As one of the developers on Red I clearly don’t think Red is a bad idea!

We saw that few people were *actually* using core javascript and native DOM scripting – most are using libraries built on top of the core language that abstract away the implementation of DOM scripting we’re stuck with. Many of these libraries also make certain programming patterns easier to do (e.g. Classes) and extend the basic language to include useful methods found in other languages (flattening arrays, transforming strings, having an actual Hash class).

We think it’s useful to take this abstraction one step further and present the developer an interface where these patterns are already implemented with minimal fuss – ruby. This is the same idea that drives GWT and pyjamas.

We’re hoping for a web environment where you can choose a language based on its strengths at the things you wish to accomplish, not because it’s the only choice.

Comment by trek — November 10, 2008

I hate when people describe javascript as an insufferable language that is not worth learning, however, I defend every person’s right to WANT to program in something different.
.
If everyone were forced to use the same server side language there would be riots in the streets. The fact is that as more and more code is written for the client side, people are going to want to be able to choose their language to run in.

Comment by genericallyloud — November 10, 2008

Thanks to Ajaxian for the writeup, and to Trek especially, who spent his entire Saturday putting the screencast together despite the aether’s great resistance to it, as well as the last two months working with me on the Redshift DOM scripting library, and the last five months letting me bounce ideas off him for Red.
.
I find the protestations of JS coders to be interesting, since they seem to come from a place that assumes I put Red together as a direct affront to their interests. Jaysmith’s “This is yet another attempt by your average narrow minded Ruby novice who wished Ruby was the only thing we should have to know” is correctly rebutted by genericallyloud’s “I defend every person’s right to WANT to program in something different … If everyone were forced to use the same server side language there would be riots in the streets.”
.
The only goal of Red is to ease the pain for Ruby coders who are used to speeding along in Merb or Rails, only to slow to a crawl when they reach the behavior layer of their application. Red makes it dead simple to add the finishing touches to a web application, without having to take two months off to learn the techniques or to learn a new library in a new language.
.
It’s a nice thought that we rack up Life Points by learning a second development language, as horia314 obliquely suggests, but consider my case: do you really think I’m better off in the long run for not just having learned a second language, but for having learned two languages well enough to transform one into the other? Who here wants to give me a medal for that accomplishment?
.
Programming is, for most developers, utilitarian. You choose the tools that get the job done, and if a Ruby programmer finds that Red is the tool he needs to finish a project in a quarter the time it would take otherwise, more’s the better. If writing straight JavaScript works well enough for him, then I recommend he skip Red. Learning JavaScript for its own sake, while enjoyable (Nosredna’s blog is a great example), is a luxury reserved for those with more free time than I’d ascribe to the average working developer – thus the proliferation of tools like GWT, Pyjamas, Cappuccino, and so on.

Comment by jessesielaff — November 11, 2008

Admirable motivations aside, GWT, Red, Ext, etc. are all leaky abstractions on top of a language that is very easy to learn, especially for those that are already using dynamic languages like Ruby.

The fact that you can actually build GWT, Red, ASP.NET on top of JavaScript is a testament to how flexible and easy it is to work with.

If you can’t be arsed to learn JavaScript, you probably shouldn’t be writing it … through GWT, Red, ASP.NET or whatever. Besides, your webapps should be able to run without javascript in the first place :-)

Comment by MorganRoderick — November 11, 2008

Seems to me we have this all backwards… how about a full blown (that is threads, ….) Javascript on the server side? Write it on top of the JVM ala Clojure.

Problem solved.

To paraphrase Shakespeare… first we kill all the Ruby programs :-)

Comment by wpoiru — November 11, 2008

@wpoiru:
The future of
Jaxer + JavaScript 3?

Comment by TNO — November 11, 2008

First of all, congratulations trek and jessie for the great work.

I tend to like javascript more than I like ruby, although I’m more proficient with the former. I, too, don’t see much reason to avoid javascript writing on the view layer in the first place. Though, I do see the argument of not writing rjs and helpers (they are both ugly to implement and limiting, to me at least).

Though, I like the idea of running ruby on a browser. As jessie said, it’s easier for the developers who don’t have much expertise in javascript. It could also be a a good experiment for us to see, when writing in ruby, what we wish was as good in javascript (maybe the good block support or symbols?)

Anyway, I don’t like gwt at all, but I think this ruby interpreter is a different ball game, and I like very much the idea.

Comment by Toledo — November 11, 2008

@Toledo:
.
ES-Harmony will support block scope instead of function scope.

Comment by TNO — November 11, 2008

Leave a comment

You must be logged in to post a comment.