Wednesday, July 09, 2008

Snakes and Kool-Aid

So, I've been playing with Python a lot in the last couple of weeks.  And although it definitely has some oddities, I am nonetheless totally jazzed up about it.  I had forgotten how much fun and power you have when doing OS level scripting.  The last time I was seriously into scripting I was using perl and Korn shell (about 7 years ago!).

So, some of the fancy things I've done lately is to integrate python with my Maven build process and let me just say it is a thing of beauty... Not the code so much, but the power of what happens when you mix these two tools.  By simply calling the python script my application gets compiled, tested, packaged and deployed to all or just some of the environments I'm working in.  All environments are kept in sync (unless I don't want them to be of course).

I've been using python to write some testing scripts as well.  Since our services are exposed via JSON we can simply fire off a request and it just works... the code looks kind of like this:

import urllib
import demjson

class Response:
  def __init__(self, jsonDictionary):
    message = jsonDictionary['message']
    self.statusCode = jsonDictionary['statusCode']

responseObj = urllib.urlopen("http://localhost/webappName/ /
responseString =

response = Response(demjson.decode(responseString))

print 'successful: %s' % response.statusCode

If you are unfamiliar with JSON here is a high level read about it.


So by taking just a little bit of effort to create a json string and sending that to a server you can do some very powerful things...

And although Python plays a small part in these tasks it is a very effective and pleasant glue that holds everything together.


But why Python you ask? Why not Ruby, PHP or Perl (the list goes on and on).  There are several answers to that question but the biggest reason is *I think* I'm going to be pushing our back-end services out onto Google's infrastructure using AppEngine, and right now AppEngine uses Python. (that is a capital period by the way)

But Python is not so bad, it's fun and powerful - but do NOT mix tabs and spaces!  Using indentation to denote blocks of code is kind of an oddity to me - I kind of like curly brackets... but aside from that - I have found Python to be a lot of fun to work with...    And I'm looking forward to rewriting our back-end services that use MySql and Java to Google's App Engine and their big Object Database.

So yeah - Google Android, GWT and eventually App Engine... I have drank the Google Kool-Aid and it is oh so tasty...




No comments: