Warning! JavaScript libraries are bad for you
If you’re a budding JavaScript coder and want to be an expert at it some day, heed my words and steer clear of JavaScript libraries. There are scores, if not hundreds of them out there and you’d do well to avoid them all. It isn’t because they’re ill conceived or badly coded. Rather, their use promotes laziness and subsequent stagnation (dare I say regression?) in the growth of a programmer who gives into the temptation to use them.
Granted, libraries are beneficial and some of the functionality they offer is down right invaluable (see: YUI Event Utility). But I’m of the opinion that any programmer that’s serious about their work should at one point or another have at least attempted to write the very same code found in those libraries themselves.
Think about it, what benefit is it to you as a programmer, to download a library, plug it in, and watch it do magical things for you? It might make your site look cool, but you’d benefit very little if anything at all as a programmer. You’d get much more out of the painful experience of knocking your head against the wall and trying to figure out how to do things for yourself. It’s a foregone conclusion that the best way to learn something is to get involved. Thus, to learn to be a programmer, you need to program!
Realistically though, time and budget constraints don’t always allow for the writing of programs from scratch. But that isn’t the point. The key is to take the time (your own time if need be) and learn the language for yourself. Otherwise, all you’re doing is glorified copy and pasting.
In as far as learning is concerned, I’ve come to the realization recently that learning JavaScript unguided on the internet is a very, very bad thing. It is after all, the world’s most misunderstood language. So if you’re eager to learn, I have a very important piece of advice for you. Don’t try and learn by using “view source”. The JavaScript you’ll find there was written by one or two people in 1994 and subsequently copied and pasted by everyone else on the internet, having mutated in the process. It’s bad, bad code. Don’t touch it. The best resource I can point you to is “Douglas Crockford’s JavaScript” (do yourself a huge favour and start by watching the videos listed on that page). As of this writing, Douglas Crockford is a JavaScript Architect at Yahoo!, and from what I can tell, knows about as much as any human being can possibly know about JavaScript. I can honestly say that I’ve learned more from him in a few days’ time than I have in the past two years on my own.
Sphere: Related Content8 Comments
Sorry, the comment form is closed at this time.



June 3rd, 2007 at 1:46 am
I agree halfway with what you’re saying. While I do think that the majority of people using JS libraries are doing so with little benefit vs. the amount of extra code, I think that libraries can be helpful if, and only if, the person using them knows what’s going on “under the hood.”
This is why I tend to favor jQuery vs. some behemoth that tries to do everything under the sun. I’d say that jQuery and the YUI event utility are quite similar in what they do - help standardize cross-browser DOM traversing and adding of events, while not taking you out of the “driver’s seat” so to speak.
It’s like the old saying - “Software should be smart, not clever.” The point at which JS libraries start doing the majority of the thinking for you is the point at which one should take a step back and say “Whoa, do I really know what’s going on here?” If not, then it’s time to do a little due diligence and learn more for oneself, and not use the library as a crutch.
June 3rd, 2007 at 2:51 am
I agree only halfway, too. When you learn from scratch, libraries are dangerous, however in order to make code work for a large team and get a whole team to develop JS, sticking to a library that normalizes browser bugs really saves the day.
I disagree with jQuery being a good choice though as its syntax is very much too alien in comparison with any native JS, you learn to use shortcuts that simply are not a given when you are to work oon a project that does not use it. There is no job description “need jQuery developer” yet, but there are JS jobs.
If you really are concerned about size (the hosted version of YUI is dead small, too, btw) then Dean Edward’s base2 is the better choice IMHO.
June 3rd, 2007 at 5:22 pm
The hacker/tinkerer in my agrees with you whole heartedly. However my OO developer instincts tell me the direct opposite. Reinventing stuff that has been done millions of times already might be a good learning experience. But then again, you could spend more time on actually doing something meaningful with your libraries instead of recreating them.
Not everything is trivial so the question is - do you want to spend months trying to replicate functionality from an existing library, debugging, optimizing and tweaking the code on your own, or would you just include the library and move on with your project?
Thanks for the link though. I will definitely check out these books. I’m all for learning more abotu Javascript the right way. :)
June 4th, 2007 at 8:52 am
I think Luke is right, after all isnt laziness one of the chief virtue of a programmer?
Libraries cannot be good or bad just by itself. They are just tools and we should decide when they help. You know what, I even think js would benefit an “import” statement so that all those libraries could reuse pieces between each other and stop reinventing themselves!
June 5th, 2007 at 1:42 pm
I cannot agree with. I just can’t! But again, as Luke said, it’s from a developer point of view. Can you imagine, my very dear friend, re-coding stuff like Struts/Spring/Hibernate just for the sake of code sanity? (sounds like Pat at the office, right?).
I agree with you that you must understand what you are doing when you do it (at least, tell this to my doctor). But your solution doesn’t fill the gap. People have to take the long road: read, learn, try, fail, understand, retry, succeed.
Anyways, hope my english is not that bad!
See ya.
June 9th, 2007 at 7:56 am
Chris: I should clarify that by saying “behemoth” I wasn’t meaning for that to imply YUI. I think that the approach taken by Yahoo is a good one, allowing developers to include what aspects are needed at any given time.
June 11th, 2007 at 4:24 pm
I agree with everything Ara says!!! He’s really a cool cat!!! and very patient!!!
When i grow up… I wanna be just like him!!! :)
June 15th, 2007 at 1:59 am
as a wise man said before:”if you want to use a javascript library,you should first know how to write one”(or something like that ;) ).