views:

7739

answers:

22

I've come across a couple questions, such as this one, and I really have to wonder why "Use jQuery" seems to be the answer when somebody asks how to do something in JavaScript. I understand that jQuery can save you a lot of time, and can help you out a lot, especially when you are doing a lot of fancy JavaScript in your site. However, in instances like this, and in many other instances, it seems like it's just jumping around the problem instead of answering the question.

I also feel like this builds too much dependency into libraries. I've seen way too many developers that simply rely too much on libraries, and if they encounter a situation where they didn't have the library, they would be completely unable to function. I feel like there are already enough developers who don't know JavaScript, without just telling everybody to not learn JavaScript, and use jQuery.

So, just to reiterate the question. Do you think there's too much of a tendency to use jQuery, for small pieces of JavaScript, when most of the functionality of jQuery isn't being used. Should developers be fluent in the use of bare JavaScript so they don't get too dependent on using libraries?

[Additional related conversation topic]

Does the existence of jQuery give too much slack to web browser developers who write the JavaScript engines? If we just have workarounds to cover all the inconsistencies in JavaScript, what pressure is there on browser makers to ensure that their JavaScript library works as it should. I feel like this extrapolates the same problem discussed in SO Podcast #36 of "be conservative in what you send, liberal in what you accept". By being so liberal with bad JavaScript engines, and using a common library to work around the flaws, we are promoting their use, and extending the problem.

+45  A: 

Yes and No.

Developers should always be able to 'rough it' if need be. But in a corporate environment where your customer wants more cowbell yesterday, you need to be able to give it to them.

Why re-invent the wheel?

George Stocker
I agree and that is basicly what my answer is getting at I love and use jQuery all the time, but I didn't use it until I understood how to do it without jQuery, I think that is why I didn't like Ruby, to much magic.
Unkwntech
Speaking of wheels, the reason we need JQuery is becuase the people building the wheels keep sending us square wheels. So we built JQuery, which is this thing we attach to the wheels to make them round. The real fix for the problem is to get them to stop sending square wheels in the first place.
Kibbee
I signed on just to +1 you for your use of "more cowbell". Than and it was a good answer.
unforgiven3
From an Agile perspective I found the business wants more cowbell yesterday and changed what a cowbell is six times on the way. So its good to have a library in that you can change your code and it "just works" not flaky cross-browser bugs.
Agile Noob
We need to know how to invent the wheel in the first place though.
Beau Martínez
+149  A: 

Do you think there's too much of a tendency to use JQuery, for smal pieces of javascript, when most of the functionality of JQuery isn't being used. Should developers be fluent in the use of bare Javascript so they don't get too dependant on using libraries?

No.

JQuery, Prototype, Dojo and countless other frameworks provide a baseline of how JavaScript and specifically DOM manipulation should work. They allow users to focus on solving business problems at hand instead of fiddling around with browser quirks.

You may as well ask if we're too dependent on java.util or java.lang.

Kevin
+1: just to piggyback: I prefer Prototype and Scriptaculous
geowa4
I'm not so hot with plain javascript; jQuery amplifies my skills and permits me to do things the right way without knowing the exact low-level how.
The Wicked Flea
@Flea: Exactly. jQuery and other libraries take the "magic" out of Javascript and allow casual Javascript programmers to make some really outstanding things. Take XHRs as an example. You can either try to compensate for all the quirks in various browsers, or use jQuery and be confident it will work.
William Brendel
+1: One thing that always cracks me up is the correlation between people who think using jQuery is overkill and people who write really naive JavaScript. In my experience, the more you actually know about cross-browser JS, the more likely you are to advocate jQuery (or your favorite lib of choice).
nezroy
+1: Agreed. Who wants to spend all their time worrying about whether or not their javascript will work in ie/firefox/safari/etc? jquery makes things much easier, and I would disagree with the statement that using jquery means you don't have to know javascript.
Kevin Tighe
+1 here too. jQuery lets you write simpler code, not more complex code.
Robert Paulson
+1 jQuery is a tool, not an answer. Somebody told me something similar to @Flea statement, and this person was worried. I told him, that even a hammer can be mastered and even a hammer can do everything about nails and walls. So the key is to Master the logic to solve problems.
Ricardo Vega
-1 I hate to be the dissenting voice but I believe a sound understanding of the underlying language is what makes you a better developer. "how JavaScript and specifically DOM manipulation should work" - Not true as they all react, behave and look (api) differently.
kouPhax
@kouPhax: Javascript and DOM vary from browser-to-browser, so you might know how to do something in IE, but not in Firefox, or vice versa. Memorizing trivia about how IE/Firefox/Safari break certain things doesn't make you a better developer. Recognizing the value of abstractions like jQuery does.
William Brendel
I think that jQuery is over suggested to people new to JS, I didn't touch a framework, in JS (prototype at the time, now jQuery) until I understood JS. Know the language before you learn the framework.
Unkwntech
@Unkwntech: but that isnt what the question is about - the question is, you already know javascript, but don't know enough about the browser specifics + low level manipulations of ajax. using a library as your base is a perfectly fine thing to do imo.
Chii
There's an important distinction to be made between knowledge of javascript and knowledge of DOM/XHR/Browser quirks etc.You could be completely fluent of Javascript but be completely caught out by the next flavour of browser to hit the market, now *that* is where the benefit of 3rd party libraries comes in - they shield you from the browser implementation details and leave you to get on with the application specific logic.
belugabob
You definitely still need to know Javascript when using jQuery, because jQ only deals with DOM and browser functions. It doesn't, for example, deal with string manipulation.
DisgruntledGoat
+12  A: 
Unkwntech
We might disagree on what we convey 'magic' to be, but to me there is no such thing as 'magic'. It's code, that works, written explicitly indeed. I just tell it what I want and couldn't care less on how to do it. That's the same as encapsulation and atomicity on a 30 member project.
kRON
But, you need to know what the framework even if you don't want/have to do it. You still should be able to do it without the framework.
Unkwntech
Knowing the framework is as simple as reading the jQuery source code. There really is nothing "magic" except it would have taken you 10 times longer to figure out the same stuff that is written in that file.
Jeff Meatball Yang
Yep, 'the magic' indeed heh. Nice one!
drlouie - louierd
"but only after I learned how to build the code myself." - do you take this approach with all libraries? If so, that's a very cautious and careful approach but I do wonder whether that's good use of your time.
Pool
@kRON (with apologies to A.C.Clarke) Magic, n.: something undistinguishable from sufficiently advanced technology.
Piskvor
+33  A: 

Do you think there's too much of a tendency to use JQuery

To use JQuery? No. It's a reasonable JS library with many purposes, in real life.

OTOH to answer SO questions, sure. It's the stock answer for anyone who doesn't know JavaScript, or doesn't even know JQuery, but answers "use JQuery" as a knee-jerk response that earns points.

I see the JQuery mafia have already voted your question down several points - congratulations. Me, I'm automatically voting down "use JQuery!" answers to questions that ask for a JavaScript solution. SO should be about learning.

bobince
+1: For SO, I agree that "use jQuery" is an unhelpful answer. Understanding the details of the various quirks is worth the effort. But once you've dealt with and understood enough of these, the answer to whether or not you should use jQuery for most tasks in the "real world" becomes self-evident.
nezroy
++I agree, mostly. I will make an exception for questions that involve lots of tedious DOM traversal; i see entirely too much broken code out there from the .nextSibling.nextSibling.firstChild.nextSibling fans...
Shog9
You'll be using most of your votes up pretty quickly each day :-).
paxdiablo
lol, yes, between that and "use regex!"...
bobince
I'm getting the impression that the best way to get points is to answer that the best way to get points is to answer "use JQuery".
intuited
+23  A: 

I used to know Javascript and the browser DOM fairly well but what was a total drag was making sure the script was cross browser friendly, even for the smallest amount of javascripting. Truth be told I don't think there's any job too small for jQuery, I wish I had it 6 years ago.

And lets face it, what's wrong with relying on libraries to get the job done and get paid? I'd sooner delegate all the mundane and stuff I'm no good at (say low level network socket programming) to a proven and debugged library written by developers who are experts in that field. Do I really want to write my own SNMP toolset, not really. Gimme a library instead.

Kev
yeah i agree - i learnt a lot of javascript and was doing all the things I do now with jQuery (inc ajax, animation, etc), but it was a serious pain in the ass. jQuery makes javascript as painless as it should be.
nickf
Herein lies the true meaning of jQuery. No will to learn the hard way, everyone wants it easy and breezy, which of course will keep people like myself paid to fix those bugs you jQuery prophets are unable to overcome. So I guess I should praise jQuery for infusing our industry with more work for us real developers.
drlouie - louierd
"No will to learn the hard way, everyone wants it easy and breezy" all very well but not an argument that holds much water. I used to program in assembler and all sorts of low level bit twiddling, I don't touch any of that stuff now. Frameworks like jQuery mean I don't have to worry about all that low level browser dependant stuff to get a business app out the door. While you're still fiddling with browser specific bugs and oddness, my app is in production earning me money for the cashflow.
Kev
+1  A: 

Kind of.

I understand why jQuery answers are so common -- it's a good, capable library that helps minimize the code you have to write to accomplish something.

But, I do think it gets abused. sometimes it really feels like a cop out. When it's a 1-line answer saying Use jQuery, then it's definitely ridiculous. But, of course, this depends a lot on the author.

On the other hand, it does help to know the core of JavaScript and DOM manipulation so you can understand why jQuery is so helpful. No library should ever become a dependency or bandwagon.

Jonathan Lonowski
However people are lazy, i only had few JS problems in my whole life that i couldnt conquer. People are lazy and ask for 10+ lines of JS when you can do that in 1 line of jQuery.
01
+5  A: 

There are a lot of questions within this question, but I'll answer the primary one based upon a lot of experience with the library itself and JavaScript: jQuery is always the answer. I don't mean to say Prototype or Mootools or Dojo can't be the answer, but I can tell you that even if you are doing simple JavaScript, then you should start with a library. For the last year, every project big or small that I work on, I always start out by saying to myself, "Oh, I just need a few selectors, or maybe an event model." Before I know it, I'm at 100+ lines of utility functions to handle that and the cross-browser issues. Given the efficiencies you gain and the ability to compress/cache the library, it really does makes sense.

The one caveat I will put to this is that you can't build a full-fledged Web application without being proficient in custom JavaScript. The library is a tool, not an architecture. It can't be the whole solution to your problem. It does not answer any questions you have related to the problem domain -- it just helps you solve the problem quicker once you know the solution.

hal10001
+2  A: 

Unlike some other Javascripot libraries, jQuery doesn't alter Javascript in any way. jQuery provides a series of convenience methods which make common and repetitive DOM manipulation tasks easier, and in doing so insulates you from some of the tedious DOM details and cross browser quirks. I don't think you can work effectively with jQuery without knowing Javascript, but you could still use it without a thorough knowledge of the DOM.

Is jQuery used too much? I think it depends on the situation, if all you're using it for is trivial DOM manipulation (e.g. showing/hiding form fields depending on checkbox values), I'd question whether the "weight" of the jQuery library is worth it. If on the other hand you're already using jQuery for other stuff on the same page (or can reasonably expect users to have it cached from another page on the site), I don't see a hassle with using it for "trivial" stuff as well.

Would I prefer a programmer on my team to know how to code against the DOM without jQuery? Absolutely. Would I want a programmer on my team used jQuery for any moderately complex Javascript task rather than deal with cross browser and other random issues? Definately.

Jim OHalloran
+72  A: 

There are two rules to follow if you want to get your answers voted up on SO.

1/ Answer every web question with "jQuery".

2/ Answer every C++ question with "Boost".

3/ Answer every optimisation question with "premature" and "evil"

4/ Learn to count properly.

Boom boom, I'm here all week, you've been a great audience...

paxdiablo
lol for 'learn to count properly'
Learning
and community wiki? With a reputation like yours , you can take a few hits :)
Learning
I always go wiki (or a comment if it's short) if it's not a real answer, so people don't think I'm seeking rep.
paxdiablo
5/ Answer every question about regular expressions with the sentence about having now two problems...
PhiLho
I think you need to start counting from 0.
JXG
...oh, and you forgot the main Rep Gainer: Answer every 'book question' with McConnell's Code Complete 2
Andreas Grech
It's not optimization questions that I respond to with "premature." Oooops, wrong site....
kyoryu
3.5/ Answer every regex question with "now You have two problems" or "use parser" ;)
naugtur
+16  A: 

Frameworks are awesome; I love 'em. Unfortunately they're no substitute for understanding the technologies upon which they're built, and upon which those technologies are built, and so on down the line. I'm all for progress in software, all for libraries and frameworks and how much more they let me do in so much less time than ever, but way more than all that, I'm dead-against being okay with not understanding exactly what it is the tools, the frameworks, are doing for you, how they work, and how to live without them.

A few years ago, I worked with a bunch of ColdFusion developers. ColdFusion is the red-headed stepchild of Web-app frameworks; it gets no respect, which is frankly a shame, because as strange as it is, and it is strange, it's actually a decent commercial product; I even use it myself from time to time. Anyway these developers had built for their employer a fairly massive little online enterprise; so successful was their collective effort that it began, as usage grew, to buckle and collapse under its own weight; every day, at peak hours, the site would slow down, then crawl, then hang, then time out like crazy, and once enough customers called to complain, the owner would rush into the tech lead's office demanding that something be done. The tech lead, a good guy, but alas one with no formal CS training and knowledge only of CF, could only respond by bouncing all the machines, declaring the problem "fixed," and sit back and wait, until it happened again. Which it did, every day, with increasing catastrophe, for years.

In the end, we discovered the problem was being caused by the obscure, counterintuitive and undocumented way ColdFusion handles connection pooling. The tech lead could've had no idea this was the case, though, because he didn't know what connection pooling was -- nor did he suspect even for a moment the config settings he'd specified himself, in earnest attempt to improve the performance problems, actually made them horribly worse. All he knew was that the ColdFusion Administrator gave him a couple of radio buttons, a textbox and a submit button; he didn't know what that radio button did, or what it actually meant to set timeouts to sixty seconds instead of ten. Ultimately, all it took was a five second config tweak, a JVM restart, and that was it -- the problem literally went away immediately, for good.

Frameworks are awesome. JQuery's awesome! But it's better to know JavaScript cold, know the DOM, know Ajax design patterns, know the intricacies of the language, know how to program asynchronously, etc., than to be a JQuery super-ninja -- because eventually, you'll run into situations JQuery wasn't designed for, or doesn't do quite right, or the project manager simply won't allow it, and you'll have to figure things out for yourself. To the OP, I say your instinct is right on the money -- JQuery is often the answer, but the real answer is not to have to rely on it in the first place.

So in other words, No. :)

Christian Nunciato
Not to mention the fact if you need to extend it to do something it doesn't do. Ignorance of the underlying technologies will only get you so far. BTW, a tech lead with no REAL technical knowledge? hmmm.
Agile Noob
Tell me about it. ;)
Christian Nunciato
+10  A: 

I think the libraries are great.
I use them all the time.
I also have my own small utilities library for when I don't need a Beowulf cluster to count to 10.

It seems a lot of JavaScript developers are really jQuery button clickers, judging from some of the questions I've seen. -- like 'how can you tell which option has been selected in jQuery?' and the like -- This is very basic, core JavaScript and developers should get to know this stuff.

I say use the libraries BUT take the time to learn the core it'll make you a better JavaScript developer.

meouw
Even if you know how to do something in JS that doesnt mean that jQuery doesnt have some usefull shortcut. A few days ago i was looking how to do exactly what you said, because i never used option in jQuery before.
01
A: 

JQuery. .

Quibblesome
Well as this isn't the accepted answer, I guess not. :)
Quibblesome
The answer is allways 42... but jQuery is a nice comment to the answer.
Gerrit
+6  A: 

It reminds me of how some people always reply to computer/OS problems with "Just buy a Mac".

There's a touch of zealotry in there.

Már Örlygsson
A: 

For every project I work on depending on what needs to be done, I either use JQuery or ExtJS. ExtJS has the benefit of well standardized components and a large community which creates plugins for them.

Ballsacian1
ExtJS started as free project, but its not free anymore. Why invest time in learning something that you might not have in your next project?
01
True, but at the same time you can buy a personal license to use it anywhere
Ballsacian1
+1  A: 

"Does the existence of jQuery give too much slack to web browser developers who write the JavaScript engines?"

That's absurd. The JS engine developers write things differently because they think their way is better. Engines continued to be developed with different standards for years and years before jQuery or any of the other major frameworks ever existed. There's no way that jQuery would be the sole thing keeping them from changing their ways, especially when jQuery developers can simply adapt the framework to new engine code.

Sure, it'd be great if all the JS engine developers agreed to use one engine, but it's a difference between what's ideal and what's realistic.

Personally, I'd rather more people use jQuery. The Internet's filled with small sites created by designers/developers that know JS just well enough to get their script working in one browser, but it breaks in the others. If those same people simply used jQuery to eliminate a good chunk of cross-browser problems, it would be a far user-friendlier place.

+2  A: 

No. Improvements in software development rely heavily on better and better abstraction layers. Back in the day, people argued everyone should write everything in Machine Language. They were wrong.

jQuery is a very useful abstraction layer that makes it much faster and easier to use Javascipt. It should be embraced fully. As people get more proficient in jQuery, they'll also grow in their Javascript understanding.

EfficionDave
I've seen many projects that abstract so far away from the original task that all the efficiency and maintainability are destroyed. Beware zealots of all flavors. Those that don't abstract enough, those that abstract too much, and those who think any single tool is always the right one.
Jay
+1  A: 

Using frameworks is an absolutely great (if not required) safety net in this cross browser slush we find ourselves in.

jQuery is not the only option. It depends on what you are doing. jQuery focuses on manipulation of the DOM. If your project is not doing a lot of that, another framework may be a better choice. It depends on that strengths you need.

However, understanding the underlying technology and how it functions is vital to writing code which property takes advantages of browser strengths, and steps around their weaknesses.

Spot
+1  A: 

jQuery should replace Javascript in the browser engines, imo.

Heck, I don't even know HTML because I know JSF.

This is why programmers don't use assembler anymore. We use high-level languages that let us focus on the big problems.

LOLtroll
+2  A: 

No.

I love jQuery since it allows me to get things done. I hate JavaScript as it just seems like you need to know so many quirks to make it work in all browsers and then the language itself is so ugly and hard to debug.

However these days people expect web sites to be super fancy and they should never leave the page and jQuery allows us developers to give this stuff and have some sort of life.

Like I know some people here have posted it is the easy way out and you have no will to learn the hard way. I disagree with this so much.

First if doing it the hard way is just so great why are we using computers? I thought it was to make our life easier? Why don't we just do everything by hand and forget using computers at least where not taking the hard way out.

Second it is still extremely hard to be a developer and we need tools to make our lives easier because people expect more and more. Back in the 90's when websites just first came out all they where static pages with some images on them.

Now web sites need to be tied to databases, use ajax, possibly fancy things going on with flash, nice web site designs and etc. This is what people expect. In the 90's all you needed was just plain old notepad that you could get the job done now if you did everything from hand in note pad you would not get anywhere.

It still is not easy being a programmer(if it was then we would not be needed). I am currently making a web site and to make it I am using jQuery, C#, asp.net MVC, linq to sql, ms sql database.

That is a ton to learn and lets face it if you get a job 90% of the time you have to know more then one thing. I can't just go I am going to learn C# and that's it your going to have a hard time finding a job since they will want on top of it .net, php or whatever. So we need libraries to speed up learning and hide us from stupid things like browser compatibility otherwise there is no way to learn it all.

"I also feel like this builds too much dependency into libraries" - Original Post

Oh I agree with this I don't know where I would be without libraries and I really don't care. Thats just how life is you get dependencies on stuff.

How many people cook these days? Most people buy fast food or premade stuff not many people cook from scratch what happens if that disappears over night what would people do? How about your car do you the in and outs of your car?

Thats why we live in a society, so we all can build off other people strengths and we don't have to do it all ourselves.

Finally in the end does anyone care if you use stuff to make things faster. I think your boss cares if you tell them that your not going to use this library and do it the "hard way" and cost the company 100's or 1000's of dollars more then if you just used the library. I think they will fire your ass so fast you won't know what hit you.

chobo2
+1  A: 

I still remembered I got jQuery and UI for just a colorpicker and some sliders (for a little drawing app). I had many copies of jQuery and UI on my github JavaScript projects. For the long term, I should include jQuery because my app gets complicated over time. (is it a hotlink to link jQuery from Google AJAX APIs?)

Sometimes the majority decides if a browser is "compatible", if every used jQuery, then every browsers will eventually use jQuery as the JavaScript/DOM specification.

When answering a question, if you are temped to answer "jQuery!", provide a rational explanation to it and how the workaround works.

SHiNKiROU
A: 

I have X number of hours I can be effective working a day and Y number of hours worth of stuff I need to get done each day. Unfortunately I'm usually in a position of Y > X. If jQuery (or any other library) can change that equation in a way without accruing technical debt then I am thankful for the library creators efforts.

Chris Lively
A: 

We had a web application that did not use jQuery, and we did a lot of work around supporting browsers like IE6.

Once we were introduced to jQuery it was a jaw-drop; wow the ability to separate javascript from pages, and find elements in the DOM.

In our new project, we went hammer and tongs into using jQuery, to find that the extra framework js and the abuse of DOM traversal has affected performance hugely.

We are back to using server-side rendering of javascript (eg. custom javascript that has variables placed correctly on the page rendered on an ASPX page).

Russell