Supporting the system clipboard in your Web applications; What a pain! Supporting the system clipboard in your Web Applications: Part Two
Mar 02

Bespin now learning some art in the Dojo

Ajax, Bespin, Tech with tags: , , Add comments

two

Roberto Saccon has given the Bespin project a nice gift, by porting the Bespin codebase to Dojo. This was a lot of work and is very much appreciated. The obvious question is going to be “Why did you decide to change from Prototype to Dojo?”

Firstly, Ben and I really like Prototype. I am a Ruby guy, so it feels good to me. I talked about it a bit here, and I will use Prototype in many projects in the future.

The state of Ajax frameworks is quite interesting. On the one hand, many of the top dogs have actively learned from each other which has lead to many of them offering similar functionality. For example, Dojo and Prototype can do a good job with DOM selectors, which jQuery is known for.

Although you can do a good job in any of the top libraries, they still differ in scope, and are optimized for certain use cases, project sizes, and functionality wants.

jQuery offers a phenomenal API for doing stuff with the DOM. It feels right. It is also trivial to extend this world, which has lead to the huge number of plugins to do just that. Because of the clean, simple API, we have seen a huge surge in jQuery usage and interest. I would say that it is optimal for designers and beginner JavaScript folk. This is not to say that it isn’t also great for experts. There is large support from folks like Simon Willison. John Resig did something amazing. If you think functional, this will be your cup of tea even above and beyond.

Prototype goes a little further in that it offers more sugar on top of the language itself. Some find the strapping on of methods on core Objects as obscene. Personally, I love it. It just feels so much nicer for me to say array.last() or array.include(thing), compared to dojo.indexOf(array, item) > -1 for example. In fact, looking at a bunch of code has me feeling a touch nuts with all of the “dojo.” items in it. My brain is starting to ignore them.

That being said, Dojo’s purity gives you a lot. It may be more verbose to dojo.byId than $, but we have no namespace pollution.

The community quickly wanted us to package up Bespin in a way that we could share things. We wanted the same, and have natural components (e.g. the Editor, Thunderhead itself), and some didn’t like the leakage of the Editor component requiring Prototype which in turn meant pollution into the global namespaces. With Dojo we can hide away nicely, and can even run a build to become foo instead of dojo if we wanted.

Since the community really wanted it, and someone stepped up and actually did it, we accepted the change. On our codebase it had some interesting side effects. For example, before hand we had Prototype, Script.aculo.us, and a slew of third party libraries to give us a bit of this, that, and the other. With Dojo, they had everything we were needing and more, so we could hg rm external/ and be done. We are also doing Comet work and the like, and it fits in nicely.

The first change here was to get Bespin working in Dojo, but now we have more work to make sure that:

  • The codebase feels Dojo-y
  • Use more of the Dojo features (e.g. dojo.keys for key handling, CSS store, Comet, …)
  • Clean up and package our stuff nicely (e.g. bespin vs. editor vs. th)

If you are a Dojo fan, or fancy getting into it anyway, please join in! There are a few Prototype things left around, so some of the spirit is there.

A bit of an aside…

A big pain with Ajax and components, is the whole “I really like that jQuery UI component, but I am using Prototype already…. grrr”. Simon Kaegi of IBM has been putting together some thoughts and code around a JavaScript module system that would enable you to say “I want service X which happens to depend on jQuery, and service Y which depends on Prototype.” I am very interested to see where this goes. We sorely need it! The annoying problem on the client is that having multiple libraries is not cheap. On the server though? Not as big a deal potentially.

5 Responses to “Bespin now learning some art in the Dojo”

  1. Nate Cavanaugh Says:

    Heya Dion,
    I’m kind of curious, and maybe you can speak more, but why dojo vs. something like YUI, Ext, or even any of the lesser ones like Qooxdoo, etc (of course, ubiquity speaks a lot for a project), but I’m curious as to the overall benefits that drove you to adopt dojo above the others.

  2. Mislav Says:

    You’re very easily influenced to leave the library of your choice for another which doesn’t even offer you enough benefits to warrant a real blog post in which we might actually *learn* something from your experience, apart from “Prototype is nice and jQuery is nice but Dojo is also nice”.

  3. kourge Says:

    Darn, and here I thought Prototype is finally used for something it’s best at: powering a rich, fat client.

  4. Kris Zyp Says:

    Dion, this is great to hear, I am really excited about Bespin and where you are going with it. It looks awesome, and I think Dojo will be a great foundation for it. BTW, have you looked at possibly using Dojo’s REST functionality for your client/server communication? I haven’t looked into Bespin enough yet, but I am really hoping that you will be supporting open standards-based communication so that it can be readily integrated with existing REST servers. Dojo’s HTTP/REST support follows RFC 2616 very closely, and may be a useful for Bespin. I think I heard Kevin was looking at using Webdav, which of course is simply an extension to RFC 2616, so it would be very natural to extend the existing functionality in Dojo for this aspect of the client-server communication. Some of our new REST stuff also ties in really nicely with Comet.

  5. Tony Says:

    I’m with Kris in that it’s great to see dojo being used here.

    I’m a developer that has now spent time developing with prototype, jquery and dojo all in actual useful cases. They all have their place but I’m also capable of saying no one library is the best for everything. For an application this size and complexity, I think dojo is the perfect fit with great out of the box building blocks.

    And I further support Kris’s mention of dojo’s data interface. I’ve recently been playing with it as a means of accessing a jsonREST rails backend and it’s brilliant.

Leave a Reply

Spam is a pain, I am sorry to have to do this to you, but can you answer the question below?

Q: What are the first four letters in the word British?