Friday, June 19, 2009

Loopy Dependancy Issues

The Bug

Working on redundant load elimination for my dissertation, I wrote a loop:

for statement in statements:
        if someCond:
                ...
                lcl = value1
        else:
                ...
                lcl = value2
        process(lcl)

That is, that is the code I thought I wrote. As it turns out, I actually forgot the final assignment and in fact wrote the following:

for statement in statements:
        if someCond:
                ...
                lcl = value1
        else:
                ...
                # lcl not assigned to
        process(lcl)

Now this is a fairly straight forward bug to find and fix, right? As it turns out, this simple typo created a fairly subtle and hard-to-trace bug.

Loving your self.

A while ago I was giving a presentation that included a quick introduction to Python. An audience member asked a question that caught me off guard: isn't explicitly prefixing “self.” to each member access annoying? Looking back, when I started programing Python, yes it was annoying. Nowadays, however, I don't mind it at all, and in fact prefer it compared to languages with implicit member accesses. At the time I couldn't rationalize why that was, however, which indicated that I needed to give the issue further consideration. In a language designed for rapid development, why should anyone put up with typing five extra characters over and over? This question lingered in my mind for a while, but things finally clicked in place when I ran into a bug while programming Actionscript.