Spotting a troublesome image morph

Mariano reported on the Pharo mailing list today a nice experiment in which he could get his gravatar picture with a simple Pharo script:

(ImageMorph fromStream:(
  ZnClient new
    beOneShot;
    url: 'http://www.gravatar.com/avatar';
    addPathSegment: (ZnDigestAuthenticator md5Hash: 'marianopeck@gmail.com');
    queryAt: #s put: '128';
    queryAt: #d put: '404';
    get) readStream) openInWorld

Executing the script in my Moose image looks like the picture below:

Gravatar.png

It's a great example of how elegant Smalltalk code looks like. But, in the same mail, Mariano also mentioned a little problem: he could not find a way to delete the image from the Pharo World.

One way to approach this is by using the Pharo halos (the meta actions associated with each visual morph). The problem with halos is that they have to be invoked by a hidden combination (Ctrl+Shift+Click). Furthermore, because the image is not a window, in the current implementation clicking on it will actually select the World morph, and you still have to know that you have to continue pressing the Alt key while clicking around to select the desired morph (see below).

Halos.png

Given that this approach can be confusing, we need to try a different approach. Any Pharo developer knows that once you have a morph object, all you have to do is execute morph delete to delete it. The only problem is how to get our hands on that morph. Suddenly, we get ourselves into a spike assessment scenario.

Let's start from what we know. We know that the result of the script is an ImageMorph, so we could try to get it simply by enumerating all instances of ImageMorph. In my image, executing ImageMorph allInstances size results in around 400 objects, so this route is not effective enough.

What else do we know? The new morph was spawned directly in the World. Thus, we could just do: World submorphs select: [:each | each class = ImageMorph]. Executing this in my image, results in two objects. Much better. But, why two? One is certainly our image. The other one is the logo of Moose. But, which is which? Hard to tell by looking at the basic objects representation.

The great thing about halos is that they are visible and they help you distinguish between morphs. What we need is a way to look at the morphs visually. GTInspector is the tool for the job. Simply inspecting World let's us visually traverse the morph tree and easily distinguish the target image (if the icon morph is not enough, you can easily get a preview of the full morph on the right hand side).

Gtinspector.png

Assessment is a human activity that is highly facilitated through proper feedback. In our case, proper meant both interactive and visual. The more you understand the nature of the feedback you need, the better you can choose your tools. And the better your productivity gets.

Posted by Tudor Girba at 13 August 2013, 10:50 pm with tags story, spike, assessment link
|