JQuery and YUI

Recently I’ve had the pleasure of developing a web app using a combination of jQuery and YUI on the front end.  These two frameworks take strikingly different approaches to JavaScript development.  YUI is massive, verbose, and feels like using a mildly over-engineered Java library.  JQuery code tends to be much smaller and functional.  I imagine jQuery is much closer to what the creators of JavaScript originally had in mind.  The ease of navigating the DOM in jQuery needs to be seen to be believed:

<script>
     //selects the first li element from the first ul under
     //the navigation element in the following HTML
     $("#navigation ul:first li:first"); //the entire JQuery code
</script>
<div id="navigation">
<ul>
   <li>foo</li>
   <li>bar</li>
   <li>Ackbar</li>
   <li>Bob Barker</li>
</ul>
<!--- subnav --->
<ul>
    <li>Some other useless list item</li>
    <li>Jeff Bain should use JQuery</li>
</ul>
</div>

However, YUI does have one advantage. The YUI GUI widgets are extremely powerful and exceed in breadth and depth the widgets of jQuery-UI. For example, jQuery has no equivalent of the YUI DataTable. Recently I was tasked with scrapping the data in a HTML <table> from a live website.  There was lots of superflious rows in the table, so I used jQuery’s AJAX API’s to download the table and remove all the irrelevent information. Once complete, I passed off the formatted <table> data to a YUI DataSource, which generated a beautiful, sortable, and resizable YUI DataTable on the fly.

Without jQuery, it would have been agany using YUI’s verbose and limited selectors.  Without YUI, I would have had to either create my own datasheet class or trust that a bug free and costumizable jQuery plugin existed.  jQuery and YUI are an awesome combination and cover just about anything you’d want to do on the web.

Disclaimer: I used YUI 2.8.  It’s entirely possible that YUI 3.0 is better, however it’s missing most of YUI 2′s nice widgets – defeating the point.

 
 
1 Comment. Leave a comment or send a Trackback.
  1. #1 • Karan said on February 16 2010:
     

    I suspected (and confirmed in the disclaimer) from your post that you were referring to YUI2. I had the displeasure of looking at it when i worked at Yahoo! It is by far the worst library API I’ve ever seen for any major project. Thankfully, I used YUI3 while in dev beta for most of my term there. Further, I was able to make API suggestions directly to the YUI3 team.

    If you look into it, YUI3 has taken a ton of inspiration from jQuery (you seem to refer to it as JQuery throughout your post). YUI2 in contrast seems like a bunch of static utility functions, rather than a cohesive framework. YUI3 widgets are much more robust to work with than in jQuery i’d say, but take that with a grain of salt as I haven’t done extensive jQuery widget building. YUI3 still needs work as many things are still painful like iterative over a list of elements.

    Anyways, glad to hear about your progress at Amazon :D

 

Comment: