Wednesday, January 7, 2009

Ode To jQuery

As someone who uses a large quantity of code written by others, I run across some pretty good stuff, some pretty weird stuff, and some pretty bad stuff, but only once in a while do I use a library and think to myself, "wow, this is pretty sweet", because after all, how sweet and awesome can a software library be. It's a software library, after all, not a shiny red car. jQuery is the shiny red car of software libraries. It's pretty awesome. Here's why:

1) It takes something that's painful and makes it close to fun.

2) I can write things in succinct fashion rather than endless document.this.that.this.theotherthing notation, and define custom behavior for basically anything on the page.

3) I can find a seemingly endless quantity of plugins to do almost anything I need to do. Need a better tooltip? Use jTip! Need a really sweet overlay? Use thickbox! Need a star rating system to help your users become more interactive? We got that.

4) Everyone else is using it and making it more and more awesome all the time. Those people are all documenting their work pretty well for the most part, and cataloging it at one central, easy to use and search site.

5) It makes things that once required a fair amount of hand-written javascript into little snippets of easily replicated goodness:
   var postTarget = "/my/awesome/path;


jQuery.post(postTarget,
{ var1: 'holla!' },
function(data)
{
handleResponse(data);
});

jQuery("#ajax_loader").show();

That little goodie does an AJAX post, then shows a little spinning wheel of wholesomeness, letting our friend the user know that we are working on their behalf. Handle response can do whatever we want, like hiding or showing something, or inserting something new and benevolent into the DOM, using the awesome show() or hide() method, or the html( yourstringhere) method. So good.

Libraries like this are important, because as anyone who works with Javascript much knows, writing code can quickly be about the JavaScript, and not about what you were trying to accomplish. When your focus is on the use case, and not the implementation, you can do a much better job, so jQuery, we salute you. You are the shiny red car of javascript development. Nerds everywhere are better for having worked with you.

Postscript: hilariously, my boss just wrote almost this exact post, albeit more polished.
blog comments powered by Disqus