The Gist of the Matter

Last time out, I started to talk about introducing a newcomer to Smalltalk. Once the basic question of which environment to use was settled, I took my protégé through one of the hoary, time-honored Smalltalk exercises of writing some broken code in a workspace, and fixing it via the debugger. Inspecting 3 frob: 7 provides some interesting jumping off points, including a chance to talk about the Magnitude hierarchy, Smalltalk’s ability to define methods within the debugger, and where and why one might place a new method, both within a hierarchy, and within categories.

We then got a little more advanced with this:

| dog |
dog := Dog new.
dog bark

We also just typed this into a workspace and used the debugger to define everything needed, from the Dog class to the #bark method. Next, we created a chicken and corresponding class that could cluck. This then provided us with an opportunity to think about a class hierarchy, so we went to the class browser, created an abstract Animal class, and moved our Dog and Chicken classes underneath it.

I then introduced some refactoring. Our Dog>>#bark method,


Transcript cr; show: ‘bow wow’



Transcript cr; show: self sound

courtesy of the ‘Extract Method’ refactoring, and then became


self makeSound

by selecting the entire body of the method and extracting that. We then pushed up Dog>>#makeSound to the Animal class.

We attacked Chicken>>#cluck similarly, yielding.


Transcript cr; show: ‘cluck cluck’

First we extracted our ‘cluck cluck’ string to a #sound method. Then we applied ‘Extract Method’ to the #cluck method body. With that, #cluck became


self makeSound

after we were offered the chance to reuse the already existing #makeSound method. Even after years of refactoring, the ability of ‘Extract Method’ to find an existing method in the hierarchy matching some arbitrary code impresses me, but when a newcomer sees it for the first time, it’s like magic. If you haven’t explored the power of Smalltalk’s refactorings, you’re programming with one hand tied behind your back.

After a little more work with the code, we decided to wrap up for the day. My protégé wanted to save the day’s progress to share with others. This shouldn’t have been a problem, but it did present a challenge. Pharo’s fileout mechanism produces a file in standard Smalltalk Interchange Format, but whatever line-end convention it uses wasn’t the one used by the platform we were running on, Linux. The resulting file wasn’t particularly readable, so we had to pass it through a filter. The filtered output eventually made its way onto Gist, a code snippet sharing service hosted by Github.

This suggests an opportunity for somebody. Both VA Smalltalk and Pharo offer a Script Manager that ought to integrate very nicely with Gist and/or Github. Anybody care to take it on?


0 Responses to “The Gist of the Matter”

  1. Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s


%d bloggers like this: