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.
