Wednesday, July 21, 2010

/me loves javascript

I attended a session on jQuery yesterday. This presentation was put on by Mike Hostetler and Jonathan Sharp.... these guys. Yes! Anyway, it was interesting to have them walk us through developing with jQuery. I waited a bit to report on this talk mostly because I was already somewhat familiar with the library, but also because I needed some time to understand what I got out of it.

There were some neat tricks that I wasn't aware of and they did a great job of explaining how the library traverses the DOM and how you should structure your code to do it more efficiently. However, there were quite a few people in the room that had a hard time following the syntax during the live coding examples. There was even a question asked whether the appendTo team would consider developing ways to make the syntax easier to write. I was thrown off by this. jQuery (in my opinion anyway) offers such an elegant way of expressing your intent. The chained method support makes it really easy and quick to drill down to the data that you want to work with. Also, the context stack lets you drill down and back up within the same chain with a syntax that can be indented and left easy to read and follow. For example:

$('tr')
  .filter(':odd')
  .addClass('odd') 
  .end()
  .find('td.company')
  .addClass('companyName'); 

This is what I really love about JavaScript. This is also what I think new JavaScript developers have the hardest time getting used to. You really need to understand what the language is doing when you start attempting things like nesting closures. But once you have that primer tucked under your belt, you can really start appreciating the advantages that the JavaScript syntax has to offer.  If you want to learn more about the good parts of JavaScript, I recommend Javascript: The Good Parts by Douglas Crockford. It's a quick read and extremely informative.

For those who are curious, Jonathan Sharp's response to the question about easier syntax was perfect: (paraphrasing from memory) "No. We would rather spend that time improving our documentation and tutorials to help developers learn the syntax". 

No comments:

Post a Comment