Dojo or JQuery

I do not wish to discuss jQuery here but apparently no Dojo blog is complete without a discussion about jQuery vs. Dojo so to get this out of the picture I post this as early as possible.

Many men, wiser than me, have written about this but here is my take on the subject. I think it is very similar to other answers you can find on the internet.

NOTE 1:  I have not used or looked at jQuery since mid 2011 and things may have changed.
NOTE 2:  Dojo and jQuery are not the only games in town, but I am  not qualified to talk about any of the other libraries.

Dojo or jQuery, quick answer

  • JQuery if you are new to javascript/web programming and only want to jazz up your pages a little. Also, if your project is only a few months and/or only a few hundred lines, pick JQuery. It will get you there faster.
  • Dojo if you have a large project and can spend time on a very steep learning curve and want to be able to create and re-use widgets, data connections and whatnot.

This answer do not take into account the “fun factor”. If your aim is to have fun JQuery will give you a quick fix but Dojo will be more rewarding in the long run. Your choice.

Dojo or jQuery, not so quick answer

First I want to point out that the question is kind of silly, really, and if you even ask you probably want to use jQuery. Dojo and jQuery are for different problem domains. Dojo is really a superset of jQuery and solve some problems that a beginner jQuery user did not even know existed.

But here is a comparison between JQuery and Dojo anyway:

JQuery vs. Dojo, round 1: Documentation

JQuery documentation wins hands down. No contest. Dojo documentation has improved enormously since I first looked at it a few years ago but it is far from good. Sometimes the only information you can get is the name of the widget. This is, in fact, my main concern with Dojo and a big part of the reason I started this blog. I hope it will somewhat ease the learning curve at bit.

The explanation is probably that Dojo is open source and contributors do not get paid to write documentation. This is, however, also true for JQuery but that project must have some magic way to get its contributors to produce documentation.

I will speak more about Dojo documentation. In the future. I have opinions.

Now, you could argue that JQuery documentation is really only good for the JQuery core and JQuery UI and Dojo contains so much more. This could be a valid argument but in reality JQuery documentation is much much easier to grasp, understand and use.

JQuery vs. Dojo, round 2: Learning Curve

Dojo does not really have a learning curve, it’s more of a step or even a Dirac-pulse. There are many things you must get right before you can even begin. It’s not easy to sneak some Dojo into your page, unless you already know Dojo quite well.

jQuery, on the other hand have a, I would say, quite flat learning curve. You just need to learn to find your way around in the documentation.

This round goes to jQuery.

JQuery vs. Dojo, round 3: Code organization

This is something Dojo does and jQuery don’t. Dojo more or less force you to organize your code and make modules (classes and widgets). As far as I know jQuery do not address this at all so you get no help here.

For a small project this may not be a problem during development, but Dojo is not only for small projects. From a maintenance point of this will probably be a problem for jQuery projects.

This is not to say a jQuery project cannot organize the code, only that jQuery do not help you with it.

Round to Dojo.

JQuery vs. Dojo, round 4: Code re-use and modularization

This is also something Dojo do and jQuery don’t. It is not only simply re-use of code that you written once but you can, for example, write some code that retrieve data from and update to on your server and let Dojo-front ends like lists and pulldown menus use this code to interact with your server.  (I’m not saying this is necessarily easy, but by design it is possible)

Dojo wins.

JQuery vs. Dojo, round 5: Page design in mark-up.

When you do things in jQuery you do it in javascript. When you work with Dojo you tend to do things in html since most widgets are as easy or even easier to specify in mark-up than in javascript. Dojo parse the html after load and modify it.

This might sound strange but it is actually very powerful and, if you have the widgets you need, you can create quite complex javascript applications without a single line of javascript (well, that is not really true, but almost). This will also encourage you to write your own widgets and you cannot do that without modularization.

Dojo win by default.

JQuery vs. Dojo, round 6: API Stability.

I cannot say for sure but the Dojo APIs seem far more  volatile than the jQuery API. The Dojo developers seem to delight in adding a new feature only do declare it deprecated a few releases later.

For example, the changes between 1.6 and 1.7 broke much of my code. Badly. I then rewrote it for the AMD API and that changed even more. I fear the 2.0 release but I must confess that I also like the new features so changes in the API is not all bad. It can sometimes also be argued if it is the API or inner workings that have changed. Such an argument would be easily solved by looking the documentation, you would think, but alas, not for Dojo.

I guess, for API stability, jQuery gets this round.

JQuery vs. Dojo, round 7: Performance.

Well, I cannot tell and from my perspective this is not a very interesting issue. I mean the difference is not big enough to be a major factor.

To me, this round is a draw.

Result: jQuery or Dojo?

It’s all up to you and your needs and preferences. Choosing Dojo comes with a cost but also with some long term benefits.

Some have suggested, as a solution to this Gordian Knot, that you can use both. While this is probably possible you will no doubt reduce your performance and double your page load times. The only reason I can see is to re-use some jQuery code in a Dojo environment but since Dojo can do (almost?) everything jQuery sort of doubt this is a good idea.

Who am I to say all this?

So I have opinions about Dojo and jQuery. Who am I and why should you trust my opinions?

Well, for starters, you should not trust anything you read on the internet and you should also remember that an advice is worth exactly what you paid for it, but here is my story:

2-3 years ago I started working on a web project that is really a REST-based web service with various clients connected to it. One client type, the main type, should be web applications written in javascript (we did a short, and expensive, excursion into Silverlight land, but I imagine you can all understand how that played out). I started working with Dojo but after banging my head against the keyboard for 2-3 months with really nothing to show for it I wen’t for jQuery. It was a very different experience and I hacked happily along and started to add functionality to my jQuery application.

After a year and a half or so (I have other tasks, so it is not 2000 hour of coding) I started to suspect I had problems. Whenever I let the project rest for a few days I noticed that it became more and more difficult to pick it up again.

So productivity went down, rather than up, over time and that is a sure sign of bad design or some built in problems in the environment. It is possible that with more experience in javascript development I could have made better but I did not. That said, I had recognized some problems and had actually built me javascript code environment, in PHP,  that packed all code into one file and made sure no file was added twice etc. I also had some code organization and file naming conventions in place, after all, after 20+ years in software you learn some things the hard way.

But it did feel like re-inventing the wheel and it did not feel comfortable to make all this that should really have been there from start.

Some 8-9 months ago I decided to take a new peek at Dojo. I noticed that the documentation looked better, much better and as a result I started to understand some things that I could not figure out last time I looked and what hooked me was the modularization and re-use aspects. I finally said “f*ck this” and told my colleges that I had to start again from scratch on the web application because I could not maintain it any longer (we all know a real programmer can write an application that is 2-3 times the size he can maintain). So I started with Dojo and have not looked back att jQuery once. I do not blame jQuery for my failure. I had no experience with javascript development and did not really have any idea on how to go at it.

About these ads

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

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: