garann means > totes profesh

a defunct web development blog

delegate and actually thinking

Sat, 07 Aug 2010 02:31:30 +0000

It's been kind of a rough month. Inspiration has been hard to come by, which is why this blog has been a little quiet. The project I'm on at work is chaos and most of the time I feel like a code monkey. No new technologies, no interesting experiments, nothing fun to think about. But there's been a high point.

jQuery's delegate has been my personal plate of shrimp lately. Another developer I know in town mentioned she was having some problems with it - prior to that I'd never even heard of it and had been quite content to go along using live for everything. As a result I started talking about it with my neighbor at work, and then he linked me to some blog posts comparing it to live. Then it came up in a few other places. Now it's all over our Javascript at work. Crazy!

During this period, there has been a lot of figuring things out and I have come to like delegate quite a bit. I like it because - unlike many things in jQuery - it's not all super-accepting and magical. You actually have to think about how you're using it. And thinking about it is not some ascetic endeavor, like coding in Perl or something. There's a real benefit to thinking it through and using delegate instead of live or bind. Sometimes using a library like jQuery makes me feel I'm not really in control of my code and I miss the old days when we did it all by hand. Using delegate, by comparison, actually feels like the tools are helping me improve the quality of my code without sacrificing my ability to make choices about how it does things.

Sometimes really trivial stuff makes me enormously happy. I'm a dork.

One of the coolest things is that I've gained is an understanding of live, which I've relied on heavily but had never given much thought to. Now that I know how it and delegate work, both seem at once brilliant and obvious. Why listen to a gazillion little anchor tags when you can listen to their container and wait for them to bubble up? I wish I'd heard about this method ten years ago. I don't know, maybe events didn't bubble the same way then. It's been educational also in terms of learning which events do and do not bubble. There are a lot of things I'd like to go back and refactor, armed with this knowledge.

I've "flipped through" jQuery Fundamentals, but this has left me feeling I should devote a weekend to reading the whole thing. There's so much I miss just looking at API documentation for things I'm already using. It's really nice to discover something rad I'd overlooked, and to actually have to think about it.