profile picture

Ryan's Ramblings

In blog form:


Django + unittest + Windmill == Goodness

January 22, 2009

I've been having my mind blown by Django over the course of this week. Not the in flashy one-shining-moment-of-brilliance kind of way, but through a slowly dawning awareness of just how much it makes possible. Or perhaps it's more accurate to say: just how much I need to re-calibrate my expectations of what should be possible, and what should be downright easy. My latest little epiphany has revolved around unit-testing, which back when I was cutting my teeth on PHP4 was far from a trivial undertaking for even a simple web-app.

read more >>

jQuery, first impressions

January 11, 2009

New projects are always a great opportunity to develop some new skills along the way. With my latest project I've jumped on the chance to tick a box that's spent far too long on my todo-list, and find out what all the fuss is about concerning the "write less, do more" JavaScript library known as jQuery.

read more >>

Extended Iterable Unpacking

December 11, 2008

If you care about these things, you probably already know: Python 3 was released last week to much fanfare. There has been some good-natured debate about the pros and cons of switching from the 2.x series, focused mostly around the big-ticket changes like better Unicode handling (pro) and breaking compatibility with all existing Python libraries (con). Instead, I wanted to share a small joy I've found in Python 3 that I'm already missing in Python 2: extended iterable unpacking.

read more >>

Preparing PyEnchant for Python 3.0

November 26, 2008

Yesterday I released a new version of the PyEnchant library with two important forward-looking features.

First, I've switched from generating the C-library binding with SWIG to the awesomeness that is ctypes. The process was very straightforward and the switch brings a couple of significant advantages. PyEnchant is now a pure-python extension module, making it much simpler to distribute and saving me the trouble of creating a separate installer for each python version. More importantly, it means that PyEnchant can now be used with PyPy! There are also ctypes implementations in the works for both Jython and IronPython.

Second, PyEnchant is now upwards-compatible with the upcoming Python 3 series. Fortunately PyEnchant doesn't use too many advanced features of Python, so it's possible to support both Python 2 and Python 3 from a single codebase. However, it does take a little work to manage the differences between string objects in the two versions. These tricks might be useful to others so I'll give a brief overview below.

read more >>

Automagical 'self' for Python Methods

September 12, 2007

Inspired by the never-ending stream of "explicit self is really ugly" comments that Python seems to attract, and wanting to hack around a little in the deep bowels of Python, I've put together a new python module called autoself.

As the name suggests, it does one very simple thing: automagically adds 'self' as the first argument in a method definition. It doesn't turn local variables into instance attributes. It doesn't change the semantics of method calls in any way shape or form. It just lets you save five keystrokes when defining a method. Will I be using this in my own code? No. No no no. I love explicit 'self'! But it was a lot of fun, and surprisingly subtle to get right in non-trivial cases such as inner classes. And I can now cross "python bytecode hacking" off my things-to-do list. (Interesting fact: python uses different bytecodes to access local variables, for optimization purposes. So turning 'self' from a free variable reference to a local variable requires rewriting the function's bytecode)