views:

424

answers:

8

Lastly I've been feeling like jQuery is slowly becoming the defacto standard in JS libraries (I might be wrong!), or at least that is more active than the rest of the frameworks.

For example, I've been looking for a fine open source calendar like Componente and found http://fullcalendar.vinsol.com/ which is based on jQuery.

We've been using Prototype for very little things, like its selector capabilities ($ function as a shortcut for document.getElementById, mainly), executing some piece of JS when the page is loaded and to issue some very simple Ajax calls.

So I guess the migration should be quite straight forward, but I'd like to know the pros / cons of migrating from Prototype to jQuery.

On the other hand, I guess that having both of them together is not a good choice, specially taking into account that the migration should be quite simple. Am I right?

Edit: some useful resources:

+5  A: 

As far as i know, Prototype and jQuery mostly overlap, except that jQuery focuses mainly on DOM manipulation, ajax, events, etc, and doesn't really have some of the capabilities that Prototype has, like classes, inheritance, etc. However, if you don't need these things, and only want a framework for cross browser DOM manip, ajax, events, etc, then I think jQuery is the way to go.

W_P
But at the same time, I don't think there's anything you can do with Prototype that you can't do with jQuery (in practice). Yeah, there are some specifics that don't translate directly, but I've yet to run into any issue that's sent me back to Prototype.
dclowd9901
agreed, just sayin that if all you need a js lib for is cross-browser DOM manip and ajax, jquery is (IMHO) the best choice.
W_P
+3  A: 

You can use them both together. Just call jQuery.noConflict(); after jQuery loads. Then you'll have to write jQuery("whatever") instead of $("whatever"). Prototype offers a lot of functionality that jQuery does not.

However, Prototype is kind of on the way out. jQuery is king now, and for some pretty good reasons. If you want the latest plugins and widgets, jQuery is going to have them.

Underscore.js offers most of the same functionality as Prototype while not messing with object prototypes and the global namespace. Underscore plus jQuery should make migrating from Prototype pretty straight forward.

noah
that Underscore.js looks interesting! thanks for the link.
W_P
+8  A: 

Prototype and JQuery cover very similar fields. I have used Prototype as my main JS Framework for many years professionally, and I'm migrating to JQuery. Here's why:

  • JQuery is faster. Prototype comes last in all performance comparisons I've seen (Random pick here). I also have a long-standing subjective impression that Prototype's effects are slower overall, especially on older machines.

  • JQuery seems to be more popular, not only, but also, on Stack Overflow. Which means it is way easier to get support, and the number of available plug-ins and ready-made code is much larger. That's not the central reason for me but together with the overall impression that jQuery is the more technically sound platform, the choice became obvious.

My only dislike is:

  • JQuery code tends to look horrible. I like JQuery and its philosophy very much, but I often hate looking at the code. If somebody came up with a dialect of JQuery that looks as beautiful and structured as plain vanilla JavaScript, I'll gladly be on board. :)

Re the comments: Additional clarification about what I don't like about jQuery's coding style.

In one word: Brackets. Thousands and thousands of them :)

Seriously though. I realize that much of what is considered "jQuery style" are shortcuts and shorthands that are entirely optional to use. Still, from a code readability and maintainability perspective, I find large chunks of jQuery code much more difficult to read and get into. Yes, that will become much easier with growing jQuery experience, but, I want my code to be readable even to a total outsider. In regards to that, jQuery is not going into the right direction IMO. Much of the code is plain ugly. It is my only major criticism of this great framework to date.

Method chaining though, @noah, and stuff like the new .delay() or what its name was, I think totally rock. I'm not saying anything against that.

Pekka
not arguing, just curious what aspects of the code you don't like?
W_P
Not arguing either: But I'm as surprised as Paul seemingly is :)
Matt
You mean you don't like code written using jQuery? e.g., method chaining and all that?
noah
@Paul @Matt @noah I updated my answer with details.
Pekka
Just curious: What's unreadable about $('.element').removeClass('foo').addClass('bar').fadeIn(300);
dclowd9901
@dclowd9901 nothing. As I said, method chaining is not what I dislike about jQuery syntax, quite the contrary. I'll try to collect some examples when I find the time later.
Pekka
Um, any complex javascript is going to have just as many brackets (or more) as doing complext jQuery. If you don't like brackets, I'm guessing you don't like Java or any C-derived language either (except maybe that freaky Objective-C syntax - still can't wrap my head around that).
Charles Boyung
Just saw another point you made - you want your code to be readable even by a total outsider. Based on context, I assume that you mean by someone without experience with the language/platform you are using, correct? If so, that is a completely unrealistic desire. Someone with no knowledge of a language is not likely to be able to understand any significant code in that language without learning at least the syntax.
Charles Boyung
@Charles no, I don't mean it in that extreme. I mean the .. in want of a better word, *physical*, immediate clarity, readability and structure of the code, that is diminished in jQuery in comparison to native JS IMO. Much of that is caused by the shorthand. As I said, I understand that much of what I'm complaining about is a set of completely optional conventions, but in effect, it still makes for code that is generally harder to read than native JS, C, *or* Java. I have some extreme examples here from SO but I'll need some time to find them later.
Pekka
+2  A: 

I have been using Prototype since 2006 and I echo Pekka's feelings about ugly code. Prototype is more elegant.

I have been a staunch supporter of the Prototype (+Scriptaculous) community but sadly, Prototype is losing mindshare and market share. Careers can be built on knowing jQuery, not so much for Prototype.

It seems jQuery people seem to be happier using plug-ins, without knowing how they work, whereas Prototype people seem to be more hard-core programmers and tend to build what they need themselves.

That being said, my transition to jQuery was not all that painful. The functionality is much the same, only with different names. There is a lot more documentation and sample code available, making it easier to pick up.

Frameworks are moving targets, sometimes leap-frogging each other in terms of speed and features. All continue to improve. Saying X is better than Y will change over time

I think Prototype's saving grace may be Scripty2. This is an amazing new animation engine using Prototype. If that catches on (and makes it to market, it's not even in Beta) there may be a resurgence in interest in Prototype. Beyond that I think it will always have its supporters, but will fade away from the mainstream.

Diodeus
I've used prototype for awhile and I really like it but the widgets and plugins that other frameworks have (like jquery and dojo) are pushing my company to abandon prototype in favor of one of the other frameworks.
tmeisenh
A: 

I think the fact that Microsoft has integrated it into the ASP.NET Ajax Framework speaks worlds for jQuery. My current employer standardized on it last year and I can find more job posting specifically asking for jQuery and any other library.

iKnowKungFoo
+4  A: 

To answer your questions directly: Yes, you should switch. And yes, you are right.

I know you said you don't like brackets...can you provide a snippet of prototype code that you consider beautiful (I'll jQuery-itize it for comparison)?

David Murdoch
A: 

I think you should. I use jquery religiously, and I'm not a Javascript Pro. It's ease of use I think, is one of the most powerful things about it.

lucha libre
+2  A: 

if you care about getting another job maybe move to JQuery. If you care about beautiful, intuitive JavaScript stick with prototoype - its not going away!

plodder