Tuesday, December 19, 2006

Cut and Paste in Rails

Rails' identity as "opinionated software" puts it midway between Perl's idea that there's more than one way to do it, and Python's idea that there's only one right way to do it. The Rails idea is that there's more than one way to do it, but the Rails way is the best way, and although we'll make the other ways possible, we'll also actively discourage them.

The problem with this isn't that the Rails way might not always really be the best way. The problem is that sometimes, the Rails way isn't even relevant. Sometimes what you want to do is neither what Rails grudgingly permits nor what it actively encourages.

I see this a lot with JavaScript. Now it's entirely possible that I just need to step up my RJS game, and if so, then all these criticisms of Rails could in fact be entirely meaningless. Take it with a grain of salt. But in the past six months I've worked on five Rails sites professionally, and in the past year, God only knows how many for fun. I don't think I've worked on a single Rails project yet where I didn't at least once have to add a Rails form handler or JavaScript shortcut to a template just so I could grab the output via view source, copy it, paste it back into the template, and then modify it to do what I really wanted it to do in the first place.

Rails is a fantastic technology, but the frustration here is that, having completely blown all its predecessors away, you kind of expect it to continue kicking ass all over the place, and this cut-and-paste workflow is not exactly crane style kung fu. If you're watching a Bruce Lee movie, and Chuck Norris takes over at the end, it's not exactly an improvement.

This isn't necessarily a design flaw in Rails, either. There's more than one type of Web app to build, and Rails is designed around a certain category of Web app. If you want to do something different with it, you can, it just won't necessarily be easy. At Canada on Rails, I heard DHH say nearly exactly those words, and he was telling the truth.

I'm not really sure what the solution is here. It's probably either a massive review of RJS, or -- perhaps more likely -- some custom code, like a plugin or something, which allows you greater flexibility and specificity on the JS side of things. I don't know if that's going to happen. I don't even know how I'd do it. The big learning things on my plate right now are Scheme, Seaside, and Rails 1.2. That's certainly enough to keep me busy.

Might be worth it, though.

3 comments:

  1. From your link:

    So I'm wondering if I'm just doing something many others have silently practiced before me or if I'm violating an unspoken rule of Rails development.

    I think you're following an unspoken rule. The auto-generation facilities are very similar to scaffolding, and using them the same way makes a lot of sense. Grain of salt, but that's what I think.

    ReplyDelete
  2. I don't think I've worked on a single Rails project yet where I didn't at least once have to add a Rails form handler or JavaScript shortcut to a template just so I could grab the output via view source, copy it, paste it back into the template, and then modify it to do what I really wanted it to do in the first place.

    That's what pushed me to fully learn Prototype, JS and totally ditch the rails helpers.

    ReplyDelete

Note: Only a member of this blog may post a comment.