Debate: Prototype vs. jQuery

With Ajax dominating the Web development scene on the client-side, the question “which JavaScript/Ajax framework is the best” has become a common one. Glenn Vanderburg’s article which compares Prototype to jQuery caused diverse responses from industry experts Douglas Crockford and Dion Almaer.

Like most programmers who’ve done Rails development, I’ve become very familiar with the Prototype library for JavaScript. Even apart from being built into Rails, Prototype was a natural choice for me. I knewJavaScriptprettywell before I started working with Prototype, and was very pleased by how the library filled in some of the weak spots in the language. Additionally, having already been a Ruby programmer for a few years, Prototype’s philosophy seemed very natural; it clearly draws inspiration from Ruby.

Along the way, though, I’ve been hearing an increasingly strong chorus in favor of jQuery. I had taken a cursory look at jQuery and was impressed, but didn’t see anything compelling enough to make me switch. But increasingly the voices favoring jQuery have included people I really respect, including (over the past few months) severalofmycolleagues here at Relevance.

I’ve now spent serious time working on two different projects with jQuery. I’ve worked alongside some experienced jQuery users, and really increased my knowledge and level of comfort with jQuery. The work has included a reasonable variety of JavaScript tasks, from simple to complex, so I’ve had a chance to enjoy jQuery’s sweet spot and also to see how it stretches.

He goes on giving a detailed list of pros and cons and leans towards Prototype:

I don’t think this makes a slam-dunk case for Prototype over jQuery. And certainly jQuery could improve; its design is not fundamentally limited. (For that matter, many of what I consider the missing pieces in jQuery are available as plugins.) It’s unfortunate that some of jQuery’s API flaws can’t be fixed without breaking compatibility, but in a future version even that may be an option.

At a minimum, though, Prototype can hold its own. For me and many others, it’s still the JavaScript library of choice.

Ultimately, I didn't find Glenn's argument to be convincing, although some of the commenters were happy to hear that they could feel good about remaining ignorant about jQuery. jQuery, being the later library, had the benefit of learning from Prototype's trials, coming up with a wonderfully expressive programming model. But mistakes were made, and jQuery's sudden popularity makes it seemingly impossible to correct those mistakes. Apparently the jQuery community forgives them. Glenn does not. John Resig is also a smart guy, and I imagine that he is frustrated at being knocked for his mistakes while being unable to repair them. Perhaps now he knows how Brendan feels.

These days, without any real context (e.g. skills on the team, what the project does) I kinda think:

jQuery is fantastic for taking a website and making it dynamic. Easy. elegant. Beautiful. If I was a designer doing a rich site I would stop here.

Dojo is fantastic for building a large scale application that will do a lot, and end up with a ton of JavaScript. Everything you need will be found there. This isn’t to say that Dojo can’t be used on the small anymore. The new core is small and fast and good.

Prototype, for me, fits in between these worlds. It is small enough to feel small (not a huge library to learn) yet large enough that I don’t jump out into creating a lot of my own code.

Of course, as Dion points out this debate doesn’t take into account a number of other great frameworks, libraries and toolkits like Dojo, YUI, GWT, MooTools, Ext JS, SproutCore and more.

It seems that Prototype is better if you want to write OO code. But jQuery's approach is just more functional and declarative, which isn't bad, just different. It's like saying that CSS sucks because it can't instantiate objects or do loop statements.

If you really want to code your whole application in javascript, you probably want to go with Prototype. Or Dojo. Or ExtJS. But I haven't yet found a better (simpler, easier, lighter) library than jQuery for just make my pages richer and more dynamic.

I used JQuery in early stage of a large intranet application, but meanwhile I switched to ExtJs of it's very clean extendible modelling and widget creation modelling behavior. JQuery is rather a rich GUI tool dispite ExtJs it is more enterprise ready. Though I don't have any experience with prototype and looking through only the documentation I think it's closer to ExtJs than JQuery is.

I found JQuery convenient to get richer ui (fast) on the site but came accross incompatibility using different plugin versions. While ExtJs is ready to use components are different to handle but the consistent usability of them become familiar after a while and is faster in many things like building grids,pages or windows like layout.

It would be great if ComScore can come up with a way to find out how many websites run on JQuery, Prototype, DoJo, ExtJs, YUI, etc., so the community can get a clear idea on adoption and enterprises that are looking for devlopers can make better informed decision instead of personal preference. One thing to add for the sake of adoption rate, MS has confirmed during their PDC, that they would support jQuery in ASP.NET MVC framework...

What's also important is the progress, IMHO jQuery has much better progress in terms of new functionality and speed. For example new improvements in 1.3 version are amazing: www.rozrobka.com/2009/01/jquery-13/

I think this discussion about the positives and negatives of each framework, what they try to accomplish, and where they are going is best suited for something a bit more personal. We set up JSConf www.jsconf2009.com for this very reason. Each of the frameworks you mentioned in your debate, and some others not mentioned, including Objective-J/Cappuccino, target specific things and do those things very well. Therefore its really a question of what is the task more than which framework/library is "better". I invite you to check out the conference as it is dedicated entirely to this discussion and others about the language of JavaScript. Cheers.