by IsaacSchlueter · 18y ago · 0 comments
jQuery is an interesting language. But I feel like it's no more "javascript" than C is assembly. It uses a lot of conventions and syntactic sugar that is not standard in the language. It's a cool and elegant, but there's a learning curve at both ends; first, you need to learn it, and then it becomes so habitual that you forget how to write "regular" javascript.
YUI, on the other hand, feels a bit more like plain old JS, which some people like and some people don't. The main problem with YUI is a lack of overall consistency in naming and whatnot. YUI 3 is coming out soon-ish, and addresses a lot of that stuff quite nicely. YUI does a really good job of not cluttering up your environment with too much gargbage--everything is under one global YAHOO object, so it's a friendly neighbor.
Avoid prototype at all costs. It monkeys around with the core object types, and adds scores of globals, which pretty much ensures that, unless ALL of your code uses prototype, and always will, you'll get unexpected behavior in some cases.
YUI was built first and foremost for use at Yahoo. It'd be hard to find a library that's more play-tested or scrutinized for performance than that. Personally, I find the core YUI libs a lot more useful than the widgets. They tend to be a bit over generalized in a lot of cases, and I can usually get better results by rolling my own.
Disclaimer: I'm a webdev at Yahoo, and I've been using YUI since its pre-OSS days.
jQuery is, of course, Javascript. John Resig didn't invent functional closures or chaining. But it seems like jQuery is designed to change the way that you write Javascript. It even says so on http://jquery.com/ It's a set of conventions, and they're not standard. I'm not saying that they're bad (in fact, I really like the jQuery style and think it's very elegant.) But there's a learning curve there, and not every javascripter is a programming language geek who would get off on learning a new style.
> then it becomes so habitual that you forget how to write "regular" javascript.
I wish that were true. Unfortunately, I still have to drop back to W3C DOM for performance often enough. For a recent feature I added, 6 lines of jQuery becomes 24 lines of JavaScript, but the speed goes from unacceptable to acceptable. (What am I doing that jQuery's not fast enough? In this case keystroke-by-keystroke search and manipulation of a 6000-cell table.)
Have you tried JQuery 1.2.6 yet? I've also had to drop down to raw DOM for performance, but I've found that many features that were unacceptably slow with 1.2.3 (mousemove events, $.map) have gotten quite usable. Events no longer copy the whole event object, map is linear time instead of quadratic, and I've heard $.extend got a major speed boost which'll speed up construction of all jQuery objects.
(Curiously, in the benchmarks folks did in the Reddit thread, it looked like Firefox was not quadratic - which implies that Firefox either has some clever optimizations going on or does crazy things with concat().)
if you or anyone is interested send me a email (tunde.ashafa AT gmail)
This is high praise indeed, and suggests to me that a) the standard DOM APIs are poorly designed, and b) that jQuery’s API is very well designed, and meshes much better with the language.
As I write most of my Javascript at Yahoo, and we can assume that Yahoo webdevs know Javascript, but not necessarily jQuery, YUI is a much better choice. (Just addressing the language conventions, not nec. the library implementation.)
To me, jQuery feels like a better javascript than javascript itself. Manipulating the DOM with plain old javascript is what feels like using C. All the quirky function names, all the weird browser variance. It's like being in college again, trying to get C++ I wrote in Windows to compile in Linux.
While jQuery is merely a library at the moment, I have to wonder if there would be any drastic speed improvement (other than negating the download time) if someone implemented the jQuery API as a browser plugin (or just tacked it on to the JS spec itself). I'm not saying that this would have any immediate practical application (since no one installs plugins anyway), but the idea sounds just silly enough to be interesting at least.