Thursday, May 28, 2009

Lunchbreak: jQuery Habits

Recently, jQuery has become by far my most favorite JavaScript framework. It's so freeing to be able to use statements like $(".restricted-admin").hide(); to hide elements en-mass, based on CSS class, or to be able to fade things with a similar statement, load page content via AJAX in two lines... yes, jQuery has become the new object of my amazement. It has made JavaScript website enhancement easy for the first time, ever.
My only concern is that it's too easy to encourage healthy programming practices. JavaScript is a funny little scripting language, in which you can create functions/objects mid-statement. So, you can make a statement like this:
$(".button1").click(function(){alert("we're inside a function!"); alert("hooray!");});
...with absolutely no grief. This is absolutely amazing, considering how much it streamlines the coding process. If I need a callback function, I can write it where and when I need it. Recently, though, I've noticed myself slipping on some of the more fundamental aspects of SE...
Particularly, the finer grains of encapsulation/"granulation" - having the ability to write functions inline has given me the nasty habit of re-writing code in a bunch of places, where I need it. It's good that I've caught myself early enough to force myself into good practices.

No comments:

Post a Comment