jQuery: It’s a beautiful framework

June 27, 2009 § Leave a comment

I’ve been using jQuery for more than 4 months now, and I love it more and more.

Through out my career I went through Prototype + Scriptaculous, brief Mochikit, MooTools, and now jQuery. But this post is not about jQuery is super awesome and other framework sucks. It’s about why I really like jQuery so much.

jQuery helps me understand Javascript.

Even though I’ve been doing web development for a while, I felt like there were still holes in my brain about javascript. There were a lot of non-obvious little things like:

  • What callback function takes as arguments. (inside AJAX its data; Inside element it could be element or event; etc.)
  • Functions Scope. (I didn’t realize that, because of function is first-class, javascript scoping is similar to Python)
  • What unobtrusive truly means. (If the web app lost functionalities when javascript is turned off, then its obtrusive)
  • What is the best practice for binding/unbinding events.

Because I didn’t have above (basic) questions answered, it’s hard for me to appreciate framework(s) that monkey-patch global objects. That’s the same reason it took a while for me to get used to Rails.

jQuery solves my complains about Javascript

Javascript language is truly verbose, akin to java. IMHO, verbosity really kills scripting language, especially while typing in interactive console.

I can only type so much of these (example):

var domElem = document.getElementsByName(‘someClassName’);

for( var i in domElem ) { console.log(domElem.class) }

In jQuery, it becomes:

$(“.someClassName”).each( function(i) { console.log(i.class) })

Such conciseness is why I like Python and Ruby and jQuery. Shorter code allows me to see what truly important.

jQuery makes being unobtrusive Easy

ready(), click(), bind(), unbind(), and more truly makes being unobtrusive super easy.

I can achieve unobtrusiveness by placing javascript logic at the end of base view/template file (Example):


$(document).ready(function() {

$(“.someDomClass”).click(function(e) {

// Do some stuff





Above technique is common place now, but jQuery makes it concise and easier to debug.

Conclusion: jQuery is awesome and worthwhile investment, for my career and for fun.


SQLAlchemy: does not call __init__

June 14, 2009 § Leave a comment

When performing query(), SQLAlchemy does not execute __init__ of the corresponding ORM objects.

Thus, if you have some logic inside __init__, those won’t get executed.

To have the desired behavior, you need to put such logic inside a function that takes no arguments, then, attach @orm.reconstructor on it.


Pylons: Testing Configuration

June 7, 2009 § Leave a comment

It’s nice that Pylons include nosetest and TestUnit as part of its testing framework.

Unfortunately, using those for unit testing inside Pylons is not trivial, not obvious, and inconvenient.

For examples:

  • I can only run nosetests on top-level directory because config is expecting ‘test.ini’ file. That’s inconvenient.
  • It is not obvious how build sqlalchemy’s engine inside tests/__init__.py. Ideally, I can build the engine based on test.ini configurations.

To answer those questions, this is how my __init__.py looks like:

The __init__ file solves various problems:

  • I can run nosetests anywhere inside project’s directory tree.
  • With simple convention, __init__ will look for test.ini file on top-level directory.
  • SqlAlchemy engine is built using configuration set in test.ini

I hope this snippet can help readers in getting up to speed in Pylons even quicker.

Where Am I?

You are currently viewing the archives for June, 2009 at RAPD.