4 ms·
It really depends on whether you like Javascript or not, and whether or not your new library-based code has to play nicely with non-library javascript. jQuery
by IsaacSchlueter 18y ago
It really depends on whether you like Javascript or not, and whether or not your new library-based code has to play nicely with non-library javascript.
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.
- midnightmonster 18y agoOn the server side (Helma/Rhino) I do a lot of functional-style JavaScript anyway, so jQuery feels very natural to me. It does have a lot of sugar, but playing with the DOM needs it. Crockford described the DOM as having been written by people who like Java[-esque things] and hold JavaScript and its style in contempt. I can't speak to the history, but the actual W3C DOM standards are such that that could certainly be true. The W3C DOM is not plain old JS. The W3C DOM is a verbose, clumsy API direct-ported from (essentially) Java into JavaScript. > 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.)
- twism 18y agohey, I'm looking for people who are interested in server side javascript and jquery to help give some input on a framework I'm working on. The framework is about a month old but the core concept is already there. if you or anyone is interested send me a email (tunde.ashafa AT gmail)
- nostrademons 18y ago> 6 lines of jQuery becomes 24 lines of JavaScript, but the speed goes from unacceptable to acceptable 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.
- Xichekolas 18y agoMap was quadratic before?! It seems like it would take deliberate effort to make it anything other than linear.
- nostrademons 18y ago$.map has an interesting quirk in its spec: it flattens returned arrays into the result. This was implemented by calling concat() with each result, but concat creates a new array for its return value. So each iteration was creating a new array and copying over the previous values, which makes for a quadratic runtime in most JS runtimes. (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().)
- ehedberg 18y ago+1 for YUI. The Yahoo team has done an astonishingly good job of demonstrating what javascript looks like if you treat it as a language worth using well, as opposed to forcing it to pretend it's something it's not (eg. prototype). I've been working with it for a year and a half, recently migrated a substantial Rails app from Prototype/Scriptaculous, and couldn't be happier.
- paul 18y agoI like both Javascript and jQuery. In what way is jQuery not "javascript"? To me, it feels as though jQuery really embraces js much more so than some other libs that try to pretend that it's java or some other lang.
- IsaacSchlueter 18y agoWell, I don't feel like YUI tries to make JS into Java. The goal of YUI is to add some extra APIs under a single global object, and pretty much let you write your code however you want. It's a library that quietly does nothing if you don't use it, and it doesn't ask you to change how you do things. 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/ 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.
- jacobolus 18y ago> then it becomes so habitual that you forget how to write "regular" javascript. 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.
- IsaacSchlueter 18y agoYeah, it was intended as such :) 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.)
- Xichekolas 18y ago> "jQuery is an interesting language. But I feel like it's no more "javascript" than C is assembly." 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.