Michael Cook’s Place

Bits of Genius in a Sea of Mediocrity

Michael Cook’s Place Random Header Image

Fixing Bugs, Python’s Fault

June 13th, 2005 · No Comments

Just a month until my birthday! But that’s not why I’m here. As it turns out, SiteMaker has been updating EVERYTHING, EVERY TIME. It took a while to track down, but it turned out to be a bug where I was testing a boolean variables to see if I wanted to force an update. The thing is, the variable wasn’t holding True or False, it was holding “True” or “False”. Now if you program, you know that strings are considered True. Therefor, “False” == True. Very confusing to find. But once I got that fixed (and a few typos), files are now skipped if they don’t need an update.

I’m going to have to blame Python for these bugs. While I love the language, there is one thing that it doesn’t have that would have fixed this. Python isn’t strictly typed. Now I think they are planning that as an option for Python 3.0, but right now it’s not there. That would have saved me some problems because my boolean variable would have been forced boolean and when I tried to (unknowingly) assign a string to it I would have at least gotten a warning.

The other bug that I fixed that was related to all this was also, in my opinion, Python’s fault. Python doesn’t require you to declare variables, which I don’t like. I’d like a version of Perl’s “strict” mode. The bug was that I was assigning a number to a variable called dateOnNewestFile (or something like that), but testing against dateOnNewest. Now dateOnNewest didn’t exist, but Python (helpfully) fixed that by giving it a value of 0, and not giving me an error. Once I caught that, the fix was simple. But in a language like C that NEVER would have gotten compiled.

These fixes mean that when I run SiteMaker with no updates needed (even though there is now more code than when I benchmarked things a month ago), the times are now .469s, .177s, .109s (R/S/Y). That is a total of 0.755s, a savings of a quarter of a second (even though there is now more data to process than when I did that benchmark). Things are also at HALF the time it was with the old code (again, there is now more to process). This is the kind of result that I was looking for.

Tags: Programming