Sponges go to camp

Chris and I went to Ruby on Rails Camp in San Jose. I do not know the valley well (or at all really) and now that I have been there I will say that IBM’s Almaden Research Center is really spooky. It looks like you are arriving at a heavily guarded orchard until you drive to the main compound. About 31 floors down is where Chris says they keep the zombie making chemical warfare research facility.

Rails Camp turned out not to be held in a subterranean nightmare factory and was very pleasant. When sessions were being decided on in the morning, someone wanted to know about RJS. Since we had used RJS/related techniques a lot, I decided that I would give a talk about it. Little did they know that deep down, I do not know that RJS is all that good an idea.

So to improvise a presentation, I stole some slides from this fantastic presentation about Rails AJAX techniques by Thomas Fuchs. It has a really funny picture of a cow-pig-sheep-chicken thing so I would pretty much suggest it even just for that. Then I realized I didn’t want to show any actual Spongecell code to give my examples and so I scaffolded out a stupid little toy thing to use. I never use scaffolding/generators, but I suddenly appreciated the ability to pump out a cookie cutter toy for this sort of thing.

Anyway, I think those slides explain what RJS is pretty well, so I will just list my gripes, which I got to at the end of the presentation:

  1. Using RJS files is usually silly. You just end up with a big pile of tiny little files that do a couple mutations on some other page, they don’t make much sense by themselves.
  2. So you use render :update. That’s actually kind of cool because you can see the flow better in your controller. But now, you have little blobs of in-line generated javascript in your controller.
  3. Even worse, your controller is now bleeding into the view logic. Why didn’t you create the view logic as the javascript of your page and then call into?
  4. JavaScriptGenerator doesn’t actually do that much for you. Seriously, look at the methods on it. Mostly it is shorter to actually write out the javascript using prototype. The scriptaculous and ajax request helpers are great because those calls can be so big to set up by hand. But the rest of it seems of limited value. And constrains you in weird ways. For instance, want to modify an element referenced by a javascript variable? I have no idea how to accomplish such a thing with the helpers.
  5. This can be overcome, but: what context are you executing in when your response gets eval’ed? What is the value of ‘this’? How do you figure out what on the page you are responding to? You can figure these things out, but it’s not well documented and much less straightforward than when you are dealing with event handling methods and callbacks on the page.

So what do I think you should do? I think you should get your hands dirty with some javascript and prototype. It’s not really any harder than learning to use the generator. RJS responses are great when used responably. Like code different view reactions as methods on the page and then use RJS to just trigger the appropriate view action with some arguments. But putting tons of view logic in RJS responses seems bad. JMHO.

The best thing that I found out at RoR Camp is that Haml looks very worth using. I had some doubts because when I initially saw it, only this blog entry seemed to work and the main site was broken and I didn’t find answers to my questions about performance and how helpers worked with this system. Well according to John Green, the author of said blog entry, it is fast and helpers (and more importantly to me, helpers that take blocks) work like in erb. So in the interest of having really good looking HTML in our views and never forgetting to close a div again, I am all in favor.

Also of note is that it sounds like IBM lurves Ruby and Rails. Which is great! Rails needs the kind of corporate support only a vast army of eZombies can provide.

Advertisements

2 Responses to Sponges go to camp

  1. There is a phrase in German that’s maybe equivalent to “swiss armyknife”, and it’s “eierlegende Wollmilchsau” (I know you’re disappointed that this isn’t all one word), or a pig that lays eggs, makes wool and has milk. Knowing that, the picture is even funnier.

    Thanks for the positive comments about RoRCamp. I’ll stay out of the RJS debate, although I do have an opinion 🙂

  2. Tom Bagby says:

    You’re right. I am very disappointed that isn’t all one word.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: