Wednesday, November 21, 2012

Things I Like About Python

Back in May I wrote a popular post about which was a better beginners language: Processing or Python.  Although I concluded that Processing was better for the audiences I tend to have in mind (that is, nontechnical members of the general public), that doesn't mean I think Python is a bad language.

I finally had the opportunity to use Python for my own project.  I have been making a simple iOS QR code scavenger hunt / story game as a (very) side project for a while now, and am trying to give it the final push to completion.  The game is defined in a plist file. I wanted to generate the QR codes automatically from the data in that plist.  I also wanted to arrange the generated images into contact sheets with the text associated with each code written underneath.  I figured this was the perfect opportunity to use Python for a real purpose instead of just as a teaching language.

The very best thing about Python is the fact that no matter what singular unit of work you need to do, you can almost always find freely available code online that does it.  QR generator? Check.  Contact sheet creation? Check.  Help with the imaging library, including drawing text? Check.  Put the pieces together and do some customization to suit my purposes, and I was off to the races.

I also like the 'scriptiness' of the language.  I felt that I didn't need to work hard to make robust and reusable code. So long as it worked for my purpose here, that was good enough.  This is a rare feeling for me.  I usually feel compelled to make the code as general and 'nice' as possible.  I loved being able to do what I wanted quickly and not worrying about what the result looked like.

But that's sort of a downside, too.  When I stepped back to look at the code from a beginner's perspective, I noted how messy and likely difficult to understand it had become.  I remember reading that Python inherently helped developers write good code (thanks to, for example, indentation to signify blocks of code).  But this experience made me believe the opposite - it's so easy to write fast code that it can quickly end up being kind of ugly.

I also had a heck of a time getting everything set up on my Macbook.  Python comes installed on OSX, but it's usually kind of old.  So I downloaded and installed Python 3.  After wrestling with the OS to get it to actually use that version for most Python-related things, I quickly found that the libraries I was trying to use didn't really work with this version.  After several hours I ended up reverting back to the newest release of version 2.  If I was a beginner trying to accomplish some relatively simple task, I would have been turned off the whole thing pretty quickly, if I even understood how to set up the environment in the first place (and I doubt much of the general public would, given how much time you are likely to spend at the command line).

So, all in all, I really like Python for my own purposes as an experienced programmer.  But I'm still favouring Processing (or, even better, something like Scratch or some not-yet-existing language theorized by Bret Victor) as a beginner language.  I could see Python being really handy once the basics are taught and some confidence is built, but I am still fairly sure I wouldn't want to begin with it if I had a choice.

No comments:

Post a Comment