Wednesday, May 6, 2009

Great video tour of many Squeak features.

Ken Causey's Squeak bug/fix reporting video actually covers way more than the title implies.

He actually walks you through finding and fixing the "bug", so during the first ten minutes, you learn:

  • creating and managing changesets
  • how to find out what menu items actually do
  • using the protocol browser

The remaining 15 minutes go into detail on the process of actually submitting the bug and fix, so probably aren't quite as interesting unless you actually want to file a bug report.

Tuesday, April 28, 2009

joining arrays with a string.

In python, I can say "-".join([1,2,3]) and it returns "1-2-3".

I was surprised to find that this wasn't available in squeak!

After hunting around the image for a while, I rolled my own version specific to my class. Then I realized what squeak really wanted me to do was add methods to the system-wide Collection class.

I mentioned what I was doing on #squeak and keithy_ mentioned Join. Turns out there's a whole bunch of public squeak code that isn't in the Universe, SqueakMap, or the default Monticello package browser.

Instead, this issue was tracked as bug 4874 in mantis.

From there I found http://www.squeaksource.com/SplitJoin.html

There's some code right on the page for adding it to your Monticello reposotiry list, but since I didn't see that, I added the URL (minus the .html) manually by clicking the "+Repository" button in Monticello and editing the URL. Then I clicked "Open" and was able to install the SplitJoin package easily.

SplitJoin adds a join: method to OrderedCollection as well as to String. The one on OrderedCollection is definitely not what you want. Instead, use the one on String, just like in python:

'-' join: #(1 2 3).

BTW: the mantis bug is marked "testing" and "fixed in 3.11" so probably this will be standard in the upcoming squeak release.

PS: turns out join: is actually implemented for all objects in SplitJoin. So if you say #(1 2 3) join: '-' you'll get back #($-) (an array containing a single minus character). This is because the #(1 2 3) array is actually inserting itself between each character of the string, but since there's only one character, you just get one character back. #(1 2 3) join: 'abc' returns #($a 1 2 3 $b 1 2 3 $c).

Seeing all available methods for a class.

One of the biggest questions I had was how to see all methods available in a class, including inherited methods.

Turns out you can get such a list programatically with SomeClass allSelectors. but that turns out to be overwhelming because base classes like Object and Morph have so many methods. (RectangleMorph allSelectors. returns an IdentitySet with 2560 members.)

But it's much nicer to use a tool, and that's what the Protocol Browser is for.

To load a Protocol Browser, right-click the class name in the normal browser, and select "browse protocol". It shows you all methods in nice little categories (protocols), and there's also a "limit" button that lets you filter out anything above a certain ancestor class. (By default, it filters out Object).

One problem: if you're using OmniBrowser in squeak 3.10, then when you click on the protocol name, you get a big nasty error. I made a patch for this, though. You can get the patch by going to the OB-Standard package in the Monticello Browser and merging in OB-Standard-mjw.405.mcz from http://source.wiresong.ca/ob/. (See my last post for a walkthrough on how to merge.

Contributing to Squeak Packages with Monticello

There was a bug in OmniBrowser's protocol browser and I managed to fix it.

Then I had to figure out how to share it. Here are my notes. (Thanks to matthewf on #squeak for the hand holding).

  • Open the OB Monticello Browser (world/open.../Monticello Browser)
  • In the left hand pane, click the package you changed.
  • In the right hand pane, you'll see a list of URLs. One of these will belong to the package maintainer. Click that one.
  • Double check your changes (equvalent of svn diff) by clicking the "changes" button with the maintainer's repository selected in the right hand pane!. This will show you a very pretty diff browser.
  • Click save. When I did this, I got a message that my version was out of date, so I had to do the equivalent of svn update:
    • Open the repository. (Using toolbar button or right click/open repository.)
    • Find the package name again on the left.
    • Select the new changeset on the right. (They're numbered, and the error message told me which one I needed)
    • Click merge
    • A little conflict detector window pops up. Just click Merge again. (When I did this, it gave a couple "ObRefreshRequired" errors, but they seemed to be display related messages internal to the Monticello Browser, so I just abandoned them.)
  • Assuming there were no conflicts in the merge, go back to the Monticello Browser and click "Save". (Be sure to enter a little message describing what you changed.)

That's it. I didn't have to create an account or anything, just added my initials. So pretty much anyone can submit a patch to OmniBrowser (which still strikes me as kind of scary). I'm sure other repositories are password protected but I haven't encountered that yet.

I don't know if that triggers some kind of notification or not, but in any case, I then joined the Omnibrowser dev list, introduced myself, and posted a note about what I'd changed.

Monday, April 27, 2009

OmniBrowser, et al preinstalled in squeak-dev image.

OmniBrowser doesn't come with squeak by default, and I couldn't figure out how to install it in the Squeak by Example image, but a guy named Damien Cassou provides a slightly modified version of the default squeak called Squeak-dev that has it installed (along with some other fun stuff).

I'm using a copy of this as my main development image. At first I thought he'd removed a bunch of stuff from squeak, but all the normal squeak stuff is still there under the hood. (Like you can get the painter thing if you right click on the world and "show main docking bar".

Finding packages you just installed.

If you just installed a package and don't know what to do next, you can look in the "recently modified" area in the (OmniBrowser) system browser, and it'll show up there.

Finding tools.

sabren: basic question: how come I can't drag a 
   squeakmap package loader into the tools flap?
keithy_: no idea
keithy_: never tried it
RandalSchwartz: I just use the world menu
RandalSchwartz: I don't even look at flaps.
...
sabren: huh.. okay, looks like the open menu is the place to go for everything. cool.
keithy_: and you can tear of menu items to make buttons
keithy_: thats what I do

(You just middle click twice on the menu to get the halo for that one list item.)

Adding fonts to squeak.

Turns out you can just drag and drop fonts onto the main squeak window and they'll show up in the font menus.

You can change fonts for various things with the world/appearance/system fonts menu.