views:

255

answers:

2

I have noticed that sometimes people have to use multiple versions of jQuery in the same page (See question 1 and question 2). I assume people have to carry old versions of jQuery because some pieces of their code is based on an older version of jQuery. Obviously, this approach causes inefficiency. The ideal solution is to refactor the old code to use the newer jQuery API. I wonder if there are tools that automate the process of upgrading a piece of code to use a newer version of jQuery. I've never written programs in in either Javascript or jQuery. So, I'd like to hear from programmers experienced in these language about their opinion on this issue. In particular, I'd like to know the following.

  1. How much of problem it is to have to load multiple versions of jQuery?
  2. Have you ever had to load multiple versions of any other library in the same page?
  3. Do you know of any refactoring tool that helps you migrate your code to use the updated API?
  4. Do you think such a refactoring tool is useful? Are you willing to use it?

Please don't consider this question closed. Current responses have already gave me good insight about the process and tools available for upgrading jQuery code. But, please feel free to add your own experience with upgrading jQuery code.

+2  A: 

your questions are all big. But from my personal experience except from very little problems in the first version which happened after migrating to later ones. Pretty much you should not run into any problems unless something is wrong with the code you have written and not jquery.

I have not seen any proper js developer who uses two different versions at the same time.

JQuery now itself offers a pretty nice api for unit testing called qunit. and if you start implementing test functions there you should be certain that your code works seamlessly.

I Use QUnit for heavy projects. which requires maybe alot of ajax requests etc. ofcourse it is not really worth it to use it for couple of animations etc.

I hope this information is helpful

XGreen
problem with your statement: so many people who arent "proper js developers" just smash as many libraries and versions as their scripts need into a page.
seanmonstar
It's absolutely a good idea to write unit tests to ensure upgrading to newer versions of libraries. But, it looks like you haven't ever had to use multiple versions of jQuery on the same page. Is that because none of jQuery updates have broken your code?
reprogrammer
I have used JQ from ver 1.2 and I remember there were couple of plugins which were causing trouble. sorry I cant remember which. but obviously they dont worth remembering.But after then until 1.4 everything has been fine. I think if you stick to certain guidelines like try to plan properly you front end before writing code and then develop plugins rather than small codes here and there.Knowing very good js is very helpful for writing good jquery but some developers due to lack of info they have about jquery rewrite alot of internal things which jq can do easily again in their code.
XGreen
JQuery is not rapidly changing. it is improving. and understanding thoroughly the Selectors, plugin Formats, Traversing functions etc along side with unit testing will ensure you do not run into troubles for future updates.
XGreen
As mrjoltcola said as well. Always[always] before looking for a plugin investigate if it can be done with much shorter and manageable code you can write yourself. And no disrespect to plugin writers out there. and some of them are flawless and really good. but many times they are more than what you need.
XGreen
Always when you come to a point that you want to write a "for", "ew Array()", indexOf, Subtring, setTimeout..etc...think again. Ask yourself can it be done using only jquery.
XGreen
Could you elaborate more on "... plugins which were causing trouble"? What kind of troubles were those plugins making? Did they brake because of jQuery API changes?
reprogrammer
There are also compatibility plugins for jquery to ease the transition of any breaking changes e.g. http://github.com/jquery/jquery-compat-1.3
Michael Haren
For example when 1.3 came out the '@' in [@attr] was removed. so it caused some code which was relying on that to go wrong. But Obviously you will investigate the api changes before you update so you will never run into this.
XGreen
Michael, Thanks for pointing me to the compatibility plugins. Since I don't know much about jQuery, I can't tell how the plugin works by just reading the source code. But, it looks like the plugin replaces the definition of some of jQuery functions by their new definitions, right? So, I'd assume that a refactoring tool that performs the replacement at development time would work correctly. But, I think a refactoring tool can do better than spitting out the whole function definitions. What do you think about this?
reprogrammer
plugins do no replace jquery functions they extend them.
XGreen
XGreen, the "@" example is a good example. What do you do when such a backwards-incompatible change occurs? Do you upgrade your code manually? Or, you just ignore the new version of jQuery library? If you upgrade your code, how do you it? Do you use any refactoring tools or you make the changes manually? Did you ever find it troublesome to upgrade your code?
reprogrammer
I usually setup a New Branch in TFS and run the solution with a new API. Look into my test units and try to debug what I can. Also look at the api docs on their site and change if needed. then afterwards put it on the test server for testers to try to break stuff. they write them down and email it to me. and I go through them.
XGreen
I heard people say alot of good things about selenium but I have not used it myself. apparently its a ff ad on and kicks ass in debugging.
XGreen
XGreen, thanks for letting me that plugins extend jQuery functions. If that is the case, the compatibility plugin is basically doing some postprocessing after calls to old jQuery functions so that they have the same behavior as their new counterparts. As I understand it, the compatibility plugin is like a run time patch. So, a static refactoring tool will be completely different from such compatibility plugins.
reprogrammer
well understood mate. the jquery functions aggregate plugins so if the plugin is written nicely they update as the api changes.I am personally not really with the compatibility plugins stuff. its better to know whats going on and fix it if possible rather than adding a layer to convert them. at the end of the day jq is for doing more and writing less so adding js is always a deadly sin unless really required.
XGreen
john resig and all those other team members are really clever people and spend alot of time getting things right and tidy. and if they make a change to the api it is for good and useful for the developer to understand it
XGreen
XGreen, from your comment on Selenium I conclude that you upgrade your code by reading the jQuery change logs. Then, you rely on tests to find out bugs due to API changes. I can imagine that a refactoring tool that helps you systematically upgrade your code will be beneficial to you. Such a refactoring tool should interact with you and warn you about any changes that might not preserve the behavior of your code.
reprogrammer
For example in jq 1.3 .live could not be chained and still cant. so they made this delegate function which does the same stuff but can also be chained. now knowing this i think is much cooler and useful than a plugin covering that up.
XGreen
I agree. The best long term solution is to upgrade your code to the new version of the library. This is why I'm interested in developing tools that help people upgrade their code safely.
reprogrammer
I wouldn't want to use a tool that keep me in the dark and fixes things for me. However if you tool was making code checks in what I have written and then compares that with upcoming api changes and then sends logs to me about the possible changes in some area of my code. then I would be using your tool.
XGreen
Now thinking about it what really would be good is if MS people like for C# and VB that warns you in your code if you use obsolete methods etc They put something similar is JQuery VS DOCS to warn you about using functions that have changed or are old
XGreen
That's interesting. So, you prefer a tool that directs you to code snippets that might break under API changes and not a refactoring tool that transforms your code interactively.
reprogrammer
I wouldn't call jq update a burden. its a fun api. It is a nice toy even when it gets naughty. But intellisence warning for obsolete functions ..oh yeah..looking forward to that
XGreen
It's good to know that you don't consider upgrading your jQuery code a burden. This shows that you really enjoy programming in jQuery. On the other hand, your desire for tools that warn you about parts of your code that might break shows that you appreciate any tool that improves your productivity in upgrading your code.
reprogrammer
+1  A: 

Ignoring the fact that you can do this with JQuery, using 2 versions of any API is unusual and error prone. It is a rare practice, but at least with JQuery, it is done.

If I were evaluating a vendor's components for a new project and there was a requirement for an older library, I'd think twice before investing in that component. Vendors who supply tools that require old verions are one of:

1) Very cautious and stability minded (good)

2) Not up to speed (not too good)

3) Low on resources (bad)

4) Not motivated to update their tools because not enough people are demanding the tool (really bad)

Of course (5) could be that their tool is so good and they have such a big customer base they don't feel the need to update it. That is ok as far as it goes, and eventually goes back to one of the other issues.

I use enough 3rd party tools to know that sometimes, a tool does a job so well that I pick it anyway, but in general, I want a tool to be current for a new project. There are a lot of "fly by night" vendors out there that just aren't maintaining their products and you don't find it out until you ask for support or new features.

mrjoltcola
I like the way you evaluate a 3rd party library by seeing how up-to-date it is. Also, thanks for letting me know that you've rarely seen 3rd party libraries use multiple versions of jQuery at the same time. However, I'm still interested to know how much effort it takes to upgrade one's code to use a newer version of jQeury.
reprogrammer
It depends on how much code and how many features; I've been using limited JQuery for years and the features I use haven't changed in a long time. I've been able to just drop-in the latest with no changes. I typically just use the DOM querying features. Sorry, I can only speculate. JQuery isn't that complex of an API, so I'd say it would be a manageable effort.
mrjoltcola
It's interesting that people still are reluctant to upgrade to newer versions of jQuery when their code breaks. Assuming that jQuery API is simple as you said, people shouldn't hesitate to refactor their code to use the new version of jQuery.
reprogrammer
There is always a change log published on jquery.com which explains all the changes for each version. Usually the things that can go wrong are minor but the details are all there.
XGreen
Yes XGreens. I'm sure any library documents its API breaking changes. And, people have to manually upgrade their code to comply with the new API. I'm more interested in refactoring tools that automate this process. That is, I'm evaluating the usefulness of a framework that helps jQuery designers rapidly build refactoring tools that update client codes. The compatibility plugins that Michael mentioned are show that such automatic upgrades are desirable. But, as you mentioned adding such extra layers of indirections are not the best way to go.
reprogrammer
I am abit uninformed regarding the existence of these automated tools that warn you about api changes. I don't know if it my ignorance or what. but the process of updating jq code for being api compliant is pretty much a manual process I think.
XGreen
XGreen, I also expected the process of upgrading client code to be manual. So, since you're an experienced jQuery user, I'd like to ask you about the burden of upgrading your jQuery code manually.
reprogrammer