Blogging to Nowhere

cat /dev/brain > /dev/null

The Long Awaited Kiwi Pycon Round-Up

OK, so this isn’t going to be as large a round up as I envisaged. Principally because its been so long since the actual event and also because only one talk video is currently available – I guess all that video editing is a big job! Also, I haven’t really had the time to investigate much of the stuff I learned about over that weekend as my current Python programming is limited to the odd script here and there (most of my programming is sadly limited to C++ and Java for reasons out of my control).

Anyway, it just so happens that the video that is up is from probably the best talk of the weekend, Anthony Baxter’s ‘Pythonic APIs’. This talk made me laugh from start to finish and taught me some things I didn’t know, watch the video below if you’re interested (brought to you by the magic of HTML5!).

As far as the other videos go, I’ve subscribed to the Kiwi Pycon Blip.tv RSS feed so I’ll be able to share them as they come along.

All that remains is to talk about my overall impressions of the conference, before they completely fade from memory! Basically I really enjoyed myself, everything was very well organised and the venue was excellent. There seemed to be some rumbling that Waitangi was a bit far away from everywhere and that the conference should have been in a city. For me the location was actually a bonus as it meant I had a good excuse to take the following day off and have a bit of a holiday!

So that’s about it, thanks to Danny, Guy, Tim and everyone else who organised. I had a great time and I even won a prize. I’m just sorry this post has taken me so long to get around to writing. Maybe I’ll be quicker off the mark next year!

Calculating Alcohol By Volume in Python on Android

Wow, I just managed to combine three of my favourite things in a single title! Recently, I’ve been getting further into home brewing, with a book I received as a Christmas present (Home Brewed Beers and Stouts, by C.J.J. Berry). Since I’d never actually measured the Alcohol By Volume (ABV) of my beer I decided to write some Python code to automate the process. The simple modules I came up with work from the command line and also on Android phones via SL4A, which makes them very useful when doing quick measurements.

Measuring ABV involves taking Specific Gravity (SG) measurements at the start and end of fermentation, adjusting them for temperature and pushing them into a simple formula. The SG measurements are taken with a Hydrometer, which is supposed to read at 20C (hence the need to adjust for other temperatures).

The temperature adjustment is done via a simple table (which I took from the book). In the script I used Linear Interpolation, to adapt it for values which weren’t available in the table. Initially I used the numpy.interp() function. However, I found that numpy isn’t present in SL4A and that installing it would be a pain since it is a C module which would need cross compiling for Android.

I therefore wrote my own interp() function, which keeps the same interface:

def interp(x, xp, fp):
    i = 0
    for p in xp:
        if p > x:
            i = xp.index(p) - 1
            break
    return ((x - xp[i])*fp[i+1] + (xp[i+1] - x)*fp[i]) / (xp[i+1] - xp[i])

I split up the code into two separate modules, sg.py (which just does specific gravity adjustment) and abv.py (which does ABV calualation). Splitting the code up enables me to take SG measurements and adjust based on temperature, without doing a full ABV measurement. In sg.py the reverse adjusted SG is what you would need to read from the hydrometer at the specified temperature, in order to achieve the adjusted reading you specified.

Since the calculations are fairly trivial the main bulk of the code is in the user interfaces. I implemented a simple command line interface which either takes arguments from the command line, or prompts the user via the python input() function. I also use the SL4A API to implement a simple UI for Android, basically the user is prompted for each quantity by a dialog box.

Anyway, there’s not much else to say, except that I’ve put the code up on Gitorious for anyone who wants it (it’s licenced AGPL). The code is in a git repository for useful Python scripts I’ve written, right now it’s the only thing there, but I’m going to track down some of the scripts I’ve written over the years and add them too – I might even get a few blog posts out of some of them!

On Language/Platform Restrictions…

Editorial Note: I know I said I was going to have a Kiwi Pycon Roundup, but I’ve been really busy recently. I’m now going to wait until the conference video/audio is posted then I can give a proper roundup and post people to the talks I found particularly interesting.

OK, today I’m having a rant. This isn’t going to be an ill conceived rant about a company, like my last one. This one is about something of a general feeling that I’ve been getting recently. I want to talk about what I call Language/Platform restriction (I’m open to a better name). This can best be described by taking an example, the best of which is Android.

So, you want to develop an Android application, but you’ve got no experience in this area. So what do you do? You head over to the Android Developer site and read some of the tutorials and documentation. To your dismay you find all the code is in Java, but you’re a Python programmer. There doesn’t seem to be any way to use your favourite language on Android, despite everyone claiming that Android is an open platform.

Granted, this example is a little contrived. The chances of any developer not knowing that Android is a Java only platform are pretty small. This isn’t even my own experience as I’m pretty good with both Java and Python (though Python is my favourite). I guess my point is that developers have preferences over which language they like to use and that these preferences seem to be being largely ignored.

Now, Android does have a working Python implementation as part of the SL4A project, but this is very much a scripting environment not an application development environment. There is no native access to the Android APIs that are required to develop a fully fledged application. Also, in my opinion its usefulness as a scripting environment is limited by the lack of a Free Software cron equivalent, to run scripts automatically.

Lest you think I’m picking on Android, this problem isn’t specific to that platform. It’s also present on The Web. “Oh No!”, I hear you cry, “The Web is an incredibly open platform, you can use any language you want!”. In some ways this is true, on the server side, yes you can pretty much use any language you want (I’ve never seen any web apps written in assembly, but I’m sure it’s possible). The client side is another matter though.

If we restrict ourselves the technologies which make up “The Open Web” (basically ignoring Flash and Silverlight), we really only have one option: Javascript. Now, Javascript has historically been a complete mess. Granted it’s getting a lot better with HTML5, but it still kinda sucks. It doesn’t have any proper OO (please don’t offer up that “a function is an object” crap, as a sorry excuse). It’s still pretty low level, certainly compared to Python and it seems to be “the language which syntax forgot”.

This worries me. It actually worries me more than the Android situation. The reason for this is that I think The Web is going to be the main application delivery platform going forward and that Free Software needs to seize on this to create a suite of Free cloud applications, just as we have for the desktop. However, the lack of a choice of languages puts me (for one) off.

There have been efforts to port Python to the browser, specifically Pyjamas and Skulpt. There are problems with both these implementations. Pyjamas is too tied to its own application framework (which come from Google Web Toolkit) and it basically ends up bringing desktop like application programming to The Web. Maybe this isn’t a bad thing, but it seems to miss the full potential of The Web. Really what we need is something that takes advantage of all The Web’s APIs, but without having to use Javscript. Skulpt, although initially promising, does the compilation from Python to Javascript on the client side, thus multiplying the overhead in doing so by the number of clients (granted its distributed, but it still seems wasteful when this only needs doing once).

I should also take a minute to mention Google’s Native Client plugin. Although its not really part of the standard Open Web technology suite, it is trying to expand beyond what Flash and Silverlight offer. Basically it’s a way to run native x86 code inside a web application and expose methods through a Javascript API. You can potentially run anything in there. There are some continuing efforts to port Python to this platform, but I think this is the wrong way to go too. It’s not really intended to be a full runtime, its more like a sandboxed version of ctypes for Javascript.

In both these situations (Android and The Web) the best option is for native support for other languages to be added directly to the underlying virtual machine. However, this doesn’t look like it’s going to happen any time soon, so we might need some other solutions. Pyjamas and Skulpt have demonstrated that it’s certainly possible to compile Python to Javascript so I think that’s a low hanging target. I haven’t seen anything more promising than SL4A for Android yet, and porting dynamic languages to run on Dalvik strikes me as much harder (given the static nature of Java).

Throughout this post I’ve kind of focussed on getting Python to run on other platforms, but what I’ve said pretty much goes for Perl, PHP or any other language. If anyone has any thoughts on this topic, or details of other projects I should check out, please get in touch. My main fear is that we’re going to end up with a situation where there is not choice of programming languages for any given platform and that some of the best languages will be left out in the cold.

Kiwi PyCon Day Two

Ahoy’hoy, again. Here’s my quick round up of day two of Kiwi PyCon. Here are the talks I attended:

  • Keynote: “Creating Pythonic APIs” by Anthony Baxter, from Google. This was really well put together, informative and above all hilarious.
  • “How Python is influencing Neuroscience Research” by Daniel Myall. Again good to see python being used for hardcore sciencey stuff!
  • “Don’t Block the GUI” by Glenn Ramsey. An introduction to basic threading and futures, I knew most of this stuff, but it was still interesting.
  • “Python in the Datacentre” by Matt Provost, from Weta Digital. Interesting to see the internals of how Python loads, it probably explains why Python is slow on embedded systems too.
  • “Wikkid Design” by Tim Penhey. About the design of a distributed Wiki system for Launchpad. Some good take home messages around choosing modules (personal recommendation and good documentation rule!).
  • Open Spaces (Track 1): “Why aren’t we using Python 3″, “NoSQL Databases” and “Robotics and UAVs”.
  • “Demystifying Unicode” by Leon Matthews. I knew nothing about unicode before this, now I know how to use it and that I should be using it!
  • “Teaching Computer Science with Python” by Carl Cerecke. An interesting look into the Canterbury CS Department’s moves towards Python for teaching.

That’s it for now, there will be more in my full round up, which I’ll write when I have time (sometime this week). Bye for now!

Kiwi PyCon Day One…

So I said I’d try to blog about Kiwi PyCon over the weekend, so here goes! This is just going to be a quick post going through a few highlights, I’ll save my detailed discussion for my full round up when I get back home.

So here’s the talks I attended:

  • Keynote (obviously) – “How I learned to stop worrying and love deployment” by Jacob Kaplan-Moss (a core Django developer). This turned me onto a few modules, which I need to take a look at some point.
  • “Freeing the Cloud one (small) service at a time” by Francois Marier – about free web services and his service, Libravatar, in particular (Francois was also kind enough to help me out with a problem I was having with it right there and then, thanks Francois).
  • “Building a distributed Key-Value store with Cassandra” by Aaron Morton from Weta Digital. This was interesting, though I think a lot of it went over my head!
  • “Packaging and Virtual Environments” by Brett Wilkins (and another presenter, who’s name I can’t remember – so sorry to him!). This was really good and turned me onto distribute, which is a setuptools replacement. I love the image on their website:
  • Lightning talks – Of which the one on Bottle was particularly interesting – I’ve been looking for a lightweight web framework to play around with, so I’ll give it a try.
  • “5 Good Reasons for Automated Testing” by Roman Joost. Yeah, I really should be using automated testing!
  • “An Opinionated Guide to what makes a Good Unit Test” by Michael Hudson Doyle. Reinforced the opinion expressed above!
  • “Amazon Web Service: An Introduction” by Simone Brunozzi. This was quite businessy, but this stuff is definitely on my “must check out” list.
  • “Python In Astronomy” by Ian Bond. I missed the beginning of this but it’s awesome to see Python being used to do some hardcore science – finding planets no less!

Well that’s my quick summary of day one, hopefully there’ll be more good stuff tomorrow, so I’ll ‘see’ you then.

Bad Behavior has blocked 1458 access attempts in the last 7 days.