views:

117

answers:

6
+5  Q: 

Overusing jquery

When using a javascript framework such as jquery, is there a realy chance of overusing the library for things that can be done simple using plain old javascript.

If so, then does this type of thing:

A: Slow code down
B: Make code less portable
C: Make the programmer less knwoledgeable about what is actually going on underneath everything

Im thinking of things like using jquery .each instead of a simple for loop. Sure this adds a bit of code but then its 'real' javascript if you get what i mean.

Maybe im just being naive.

+4  A: 

Well, I suppose there's a chance, but in general the advantages far outweight the disadvantages.

In general

a) it may slow code down slightly if you're doing something that wopuld be simple in pure JS, but in most cases that';s been optimized in jQuery anyway. On the other hand, the naive way you'd do much of anything complicated is probably not as fast as Reisig et al will have done it.

b) It certainly makes code less portable in the sense that it's going to depend on the jQuery libraries. On the other hand, it will be more portable across browsers and versions, which is the more important consideration.

c) yes, it may conceal some of the javascript magic. My experience, however, is that you eventually have to learn it anyway; in the mean time jQuery makes you much more productive, much faster.

(Note, also, that these points actually apply to most libraries. jQuery is my favorite, but I write a lot with dojo, and have used prototype, scriptaculous, and YUI happily.)

Charlie Martin
+1  A: 

I figure if I'm going to load a library on a page, I may as well use it as much as I can. I try to get the bang for my buck (so to speak).

Noodles
+5  A: 

B) it makes code more portable, not less, because differences between browsers are handled by the framework implementation.

+1 - Was about to write this. Cross browser compliance is one of the main reasons for using libraries in JS.
Peter Ajtai
A: 

Of course, like any "new" technology, it is overused. It's the same for things like Linq or CSS adapters for .NET. The rule is if you can make it simple and efficient, do it!

netadictos
I agree that it is interesting to use a framework to centralize things. Notwithstanding, there are things that are almost inmutable and built-in that are faster. About performance of each / for, read for example here: http://jquery-howto.blogspot.com/2009/06/javascript-for-loop-vs-jquery-each.html or here: http://net.tutsplus.com/tutorials/javascript-ajax/10-ways-to-instantly-increase-your-jquery-performance/. The overuse of new technology I think is evident, I remember when we started with web services, we have used them when innecessary. I don't understand the downvote.
netadictos
+1  A: 

AS for slowness, I would think that the initial load of jQuery would tackle most of your functionality. If you are loading 20 plugins then you may run into some issues.

jQuery is no less protable than any other JS file. Even less so if you are using a CDN.

I do tend to agree with the third point. I tend to not fuss with much actual JS anymore I just use jQuery to do everything, within reason.

Overall, I think jQuery and other JS lib's are one of the best things to happen to web development in the last bit.

Dustin Laine
+1  A: 

The really great thing about jquery is they have already come up with some quick, smooth code that helps to protect you from cross-browser hazards. So, I am sure anything can be abused, but the benefits of knowing that my code is more likely to keep up with future browser changes simply by updating jquery's API without worrying about your my outdated javascript code gives me a little more peace-of-mind. Is it perfect? Noooooo. But right now, it makes my life sooooo much easier both now and in the foreseable future. If you write "raw" javascript-only code, then if one single browser changes the way they handle your situation, then that is one less segment of users that can efficiently view your site.

exoboy
Let's remember he was talking about a simple "for" loop against "each", that is not goint to change, for sure.
netadictos
You would think that... but I keep reading articles that talk about how inefficient the for looping mechanism is in comparison to for-in, each(), and a host of others. So, while it might not disappear today, you really never can tell. Of course it is much more likely to not change for a long time, but I was really speaking in terms of the overall scheme of things... the 10,000 foot view. I was not really targeting any one particular function or any one single method...
exoboy
Ok, I understand what you say, and I agree that it is interesting to use a framework to centralize things. Notwithstanding, there are things that are almost inmutable. About performance of each / for, read for example here: http://jquery-howto.blogspot.com/2009/06/javascript-for-loop-vs-jquery-each.html or here: http://net.tutsplus.com/tutorials/javascript-ajax/10-ways-to-instantly-increase-your-jquery-performance/
netadictos