Jul 21

Yesterday I was helping a fellow coder from another team with ASP (Old school ASP, not ASP.net). I know very little ASP, since I’d dumped it a long long time ago. But I thought logic is logic, no matter what language you code in. It involved creating a html table based on some esoteric conditions. Like we have a table with some rows with some variables(essentially tri states (High,Med,Low)) and weeks, Now if a particular condition is high for 2 successive weeks, the weeks and the other data should show up on the page so that the uber-user can enter his feedback. The catch is that if the condition is high for 3 weeks, it should come up with 2 rows (1,2),(2,3), If its 4 then 3 rows.

Pretty straight forward, I thought. But then I ended up having to nest 3 cursors (RecordSets) in a loop to come up with the solution. Everytime you’re done with the recordset, you have to set it to nothing (So much so for garbage collection). Then a dozen response.writes for writing the table inside the deepest loop. The whole chunk of code was looking so dirty. If it was in Python, I’d have rather rewritten it to clean it up. I’ve gotten to a point, where I hate any unelegant code, at the very sight of it.

I guess the title of the article is slightly misleading. It should rather be titled Python vs VBScript. Or maybe, its not just the language thats supposed to be blamed. I’ve maintained enough JSP code and even my early CherryTemplate based code (I use HTMLTemplate) to learn that the problem is much deeper than the language, The root of all evil in Web Programming is page based templates, which leave you with almost no option but to mix the logic with the display (HTML). Yeah you can always write Classes and then instantiate them in the JSP templates, pretty much the same story with PHP, includes in ASP serve a similar purpose, but some of us programmers are lazy (Atleast me!). We want to get the job done ASAP, and we’re encouraged to do that. So, we mix things up.

I like HTMLTemplate , It allows me to cleanly seperate the view (HTML) from the code. Every other framework does that. But HTMLTemplate forces me to do that. Heck, there’s no other way of doing things with it. Its pretty much the same story with xml templates in Nevow. TAL from Zope is pretty much the same. Looking at the ZPT page, I found that there are ports of ZPT to most other languages. Why aren’t most of us using these things yet ?

Now for my rant on Rails. Like everybody, I saw the video and was quite impressed. But we’ve been doing most of this stuff in Python for ages now. Ok, I confess I’ve not used an ORM for Databases, but most of the apps that I work on are better off using raw queries, which I can later optimize for performance. Writing SQL queries is not that hard, and if they are hard, then I write a class to do the job, Give it a bunch of variables and it’ll cough out a query based on em. What I like about CherryPy is the flexibility. I’m free to use whatever templating framework I need, Like HTMLTemplate or Cheetah or CherryTemplate or even plain old dict based string formatting in Python. Any kind of DB, AJAX, my own filters et all…

So, though Rails is cool, I don’t find a reason to switch to a different language when I have the same level of power and a lot lot more experience(My experience with Ruby is Zero) with Python.

Jul 19

I’m blogging after a short hiatus, A little more than a month. Been learning Nevow lately. One piece of advice for all Nevow rookies like me. Grab copies of both Nevow and Twisted from SVN, instead of using the standard tarball downloads. The download file for Nevow is fairly old. And theres a lot of action happening on the codebase, so its best to grab stuff from SVN. I normally use CherryPy for quick hacks, was using Twisted for implementing a custom protocol a long time ago. I first got interested in Nevow for Livepage, Nevow had something like Ajax long before the term ajax was coined. One thing which is hard with xmlhttprequest based techniques is maintaining a downstream link, i.e notifying the browser when an object on the server changes. We normally get around this problem by polling the server periodically. Livepage, I’ve been told maintains a persistent downlink connection. Have’nt gotten to the point of using Livepage yet.
Another interesting development is CherryPy 2.1 with WSGI support. Benchmarks on the site indicate a significant performance increase over CherryPy 2.0
Been using del.ico.us like crazy for some time now. There’s a Python lib for the API as well. Gotta play with this thing on the week end.