One day with App Engine and Python

So I finally decided to play around with Python and App Engine a little – had a little FriendFeed project that’s been kicking around my brain for a bit. Bear in mind I’ve done exactly one project in Python and that was over a decade ago, so, you know. This is all pretty much the knee jerk reactions of a Perl guy. All help from Pythonistas and App Engineers appreciated.

Overall, I found Python pretty pleasant to work with. The indenting thing is odd but not objectionable, I liked that the files I got with AppEngine showed an indent level of 2 spaces (I usually use 3, but applaud anyone going less than that, I rarely see it though). Understand, I read the docs only when something was erroring out, so may be missing things. I was annoyed that you had to cast variables all over the place… I’m used to my language Doing What I Mean. This happened a lot trying to concatenate strings, I mean, I needed to do this kinda thing all over the place, more or less:

self.response.out.write(“Here is the count: “, str(myobj.count), “\n”)

Bleah. But you know, ultimately, not a big deal. I was also annoyed by the weakness of their Lambda functions. I mean, you can only create anonymous functions in python that have exactly 1 expression in the body? Annoying, especially given that they went and added map, reduce and filter right into the language. You have to create a named function for anything complexier than one expression will allow. That seems kinda tired.

Lastly, I think that Python lacks a block scope, which also kinda sucks. So it’s smallest scope is function? And outside the function the smallest scope is global? Am I reading that right? That’s pretty weak sauce, if you ask me.

Again, these are mostly either wrong conclusions (since I just started) and/or Perl culture shock (although, I really do think that scope thing is a problem if I read the docs right).

Moving along to AppEngine – I downloaded their Mac Launcher and after a surprisingly small modicum of futzing around finally figured out how to make something happen, which was quite satisfying. AppEngine’s pretty easy to work with, but the documentation, leaves a little to be desired – much futzing and trial and error ensued, but ultimately I was able to impose my desires onto a functioning app running on my desktop.

On the one hand the Data Store is pretty interesting to work with. It’s easy and really good for simple things. But without joins or really any level of complexity in the query language – it’s a little stifling, at least for me. I suspect it mostly requires a very different frame of mind in creating the schema with much more denormalization and pre-calculating of stuff to make it sing. Hopefully, that’ll come with time.

I’ve been stymied by the URL Fetch API, though. I’m trying to figure out the Location of a 30x redirect but URL Fetch insists on simply following the location and returning the actual content. If anyone knows how to do what I want, please let me know. Also the lack of any sort of cron like functionality is wierd, although easy enough for me to cron a commandline curl to hit a page periodically.

Still what’s compelling about AppEngine is the mystical allure of not worrying about scale. I spent 0 time worrying about efficiency (which mostly is because I wanted to get things done in the easiest most obvious way and my Python skillz are totally not mad, sane skillz are what I have), which actually seems to be putting the hurt on my desktop this morning. I need to spend some quality time with their Templating system (Django’s, I believe) to impose a little beauty on my app. If anyone happens to know how I can score an actual AppEngine account to load up my app, why I’d be right appreciative.

Overall, I’m pretty positive on the whole thing. Have some more spit and polish to apply but it was pretty fun working through all this stuff. I’m sure any Pythonista would cringe at the code I’ve written, but hey, it’s working and that’s what counts. Have you been playing around with AppEngine? Got any tips for me?

Oh, also, it’s crazy that Python went and turned ye standard ternary operator (?:) into an X if Y else Z construct, but then don’t take that the next step and simply allow a very pleasant X if Y construction.

blog comments powered by Disqus

Not Found

Sorry, but what you are looking for isn't here...