Wednesday, July 22, 2009

Ighalsk - release 0.1.6

I've just released v0.1.6 of Ighalsk here. (Yes, I skipped v0.1.5 - I actually made a tag for it in Subversion, but then discovered when I tested the zip file that I'd forgotten to check in a new file ... so it got superseded by v0.1.6 immediately.)

As planned, Ighalsk now has quests. True, each quest has only one level at the moment (there will eventually be 5 for each), but it's a start. One of the quests is to "defeat Lord Apathy in the Tunnels of Lost Dreams". For those who lack motivation for this quest, here's some background.

Lord Apathy is the least powerful of the Lords of Illusion. He sits (or, more often, sleeps) in a half-completed maze of tunnels filled with lost dreams, brooding, bitter and unkempt. From here, he spreads despair, hopelessness and, yes, apathy across the countryside. He should probably be stopped.

Another quest is "Defeat Elannonen the Lost in the Necropolis of Zezun". Queen Miala points out (will point out), "Why do we keep on building these cemetaries and tombs and graveyards if they just fill up with undead? Why don't we start cremating our dead?"

The final quest present in this release is "Defeat the Witch-Spider Skkshryx in Arachnaxos", about which I have little to say except that the witch-spider is not fond of vowels.

Tuesday, July 7, 2009

My Own Personal Sadness Troll

The inspirational Havi Brooks has several posts about talking to your monsters (fears, anxieties, stresses) about what they need and why they're doing what they're doing. She even suggests bringing in an (imaginary) negotiator if that would help.

My biggest problems at the moment aren't fears so much as sadness and anger. So I set up an interview with my own personal Sadness Troll. I picture him as huge and hairy, with big, weepy eyes - in fact, he looks a lot like the Muppet who helps to sell used cars in "The Muppet Movie". (Thanks to Wikipedia, I've now discovered that this Muppet is called "Sweetums" - more about Sweetums here!)

This was how the interview went. (I'm not sure exactly what the interviewer looked like, but let's assume he looked a bit like Kerry O'Brien.) There has been some post-production editing, but the basic insights were there at the start.

Interviewer: Why do you make Luke so sad?
Sadness Troll: I have to keep reminding him that he needs to be successful! So yes, he gets sad when he doesn't measure up, but he needs reminding!
Int: Why does he need to be successful?
ST: Hmmm ... not sure. Because a lot of his identity has been bound up with that ever since school? Because people expect it of him?
Int: Could he try being different instead? "Dropping out" in some metaphorical sense? Become a "virtual" hippy or pilgrim? You know, he's got the hair to be a hippy ... What about "be the change you want to see"? How about if he tried to be compassionate instead?
ST: Hmmm ... I'll have to think about that, but it might work.
(Sadness Troll wanders off, looking less depressed for the first time in a long time.)

Another part of the interview that got cut from the program was this:

ST: We need to see results, or we'll never know if he's getting anywhere!
Int: Isn't that negative reinforcement? Don't you remember that exercise that Luke did where he listed all the positive motivational techniques that worked for him?
ST: ... oh yeah. That's right. How about that.

Besides Havi, it looks to me like the interviewer also drew on Personal Alignment from the Core Protocols - identifying a goal, working out what's blocking you, what you'd need to overcome that block, and repeating as necessary. Finally, the exercise that I've done previously to list postive motivational techniques came from Barbara Sher's "Live the life you love And Stop Just Getting By". For the record, at the top of the list were:

spirituality and praying; competition (including against myself); receiving praise; getting help from friends; starting small; deadlines (if well-defined and realistic).

I gave these an A for how well they work for me; shaming got a D, and scolding, built and lecturing got an F.

So maybe there are some techniques that the Sadness Troll could pick up ...

Ighalsk - in which I discover StringIO

The suite of unit (more or less) tests that I run for Ighalsk currently takes about 11 seconds to run 281 tests (for the current version with Subversion revision number 58). This is not too bad, but I've read about projects running more than 1000 tests in less than 10 seconds, perhaps even less than 1 second. In particular, the suggestion is to avoid file accesses in unit tests (see for example Michael Feathers here).

When using Java, I think the idea is to accept an abstract Reader object as a parameter, which can be a FileReader object in the actual program, and can be mocked as a StringReader (or is it ByteArrayInputStream? so many choices!) in test code for speed. (On checking, I found that the example I was thinking of is actually for .NET ...)

I was planning to implement my own FileReader and StringReader objects in Python, but then I'd have to unit test those as well ... when, reading through the Python manual, I discovered a class called StringIO!

Its description begins, "This module implements a file-like class, StringIO, that reads and writes a string buffer (also known as memory files). See the description of file objects for operations ..." - which is exactly what I wanted!

I've started using this approach (mocking file objects using StringIO) in new classes, but I still need to switch to it for existing classes. In most cases, it should be a matter of opening a file and passing in the file object before calling a function instead of passing in a filename and opening the file inside the function, though this still means that there'll be at least one class somewhere that will still have to open some files ... but separating out this functionality should mean that file I/O only needs to happen in a small number of unit tests. Yet another treasure hidden away in the depths of the standard Python libraries!