Wednesday, July 29, 2009

Importance of trying

I had an experience recently that reinforces a good lesson I think. That being how different it is to learn passively (by reading) versus actively, by trying to use it to accomplish something.

In this case it was attempting to provide the functionality I've been working on the last couple months that sits in an extension to Firefox and implementing it in a bookmarklet.

This first led me to refactor some of the code that I had written for the extension so that it separated out the parts that were specific to the firefox extension from the pieces that were more general and could be leveraged by something else (in this case, in anticipation of use by the bookmarklet).

Then followed learning about how bookmarlets work, common approaches, and the like.

Early use of the bookmarklet was successful, but I ran into a fatal problem. What I'm doing requires access to the entire web page, including all iframes. Because of security concerns, browsers disallow cross-domain javascript access into iframes. Which means essentially that running in the context of launching from a bookmarklet, I don't have enough "power" to do the things I want to do.

So in the end, the whole bookmarklet approach had to be abandoned. But the exercise was a great benefit:

1. The refactor of the javascript code that I already had makes it more flexible and easier to deal with.

2. I learned all about bookmarklets and how they work.

3. I learned more about the internals of the web browser, and specifically the issues around the challenges that cross-domain iframe access presents.

Of course, I would have been happier if the bookmarklet approach had also panned out - but I'll take what I can get.

Wednesday, July 8, 2009

So easy

I started the day with the task of deciding how I would go about integrating a ratings system and commenting into a service that I'm building the prototype for.

I've already been enjoying how easy it has been to get functionality up and running using a port of Django for Google App Engine called App Engine Patch, and also enjoying in general getting more comfortable with the Python programming language.

Anyway I decided first that I would look into integrating a third-party commenting system to address that piece, and thought I'd pick Disqus, which I've seen on various blogs and like (for reasons of threading and such).

After copying and pasting a total of about 17 lines of javascript into the appropriate template for my Django app, that was done.

I then spent some time putting together an implementation of ratings natively in the Django app. Then I went looking for a javascript UI piece, and in the process came across a ratings system that is part of something called JS-Kit.

A little bit of testing later, and removing the start of my ratings implementation, and 7 additional lines of code into the same Django template that took the commenting code, and I had ratings as well.

So, at the end of the day I had learned a lot, but also got ratings and commenting into the application at the cost of 24 lines of javascript.

Eventually I may rip these out in favor of native implementations, for various reasons. But for now - thanks to Disqus and JS-Kit for getting these out of the way!