Software Engineering Matters

giving a little more thought...

Finding Code in Squeak

Posted by Nicholas Chen Wed, 30 May 2007 22:45:21 GMT

This post is inspired by the contents of this entry at the Squeak Wiki FAQ. I just added some pictures to make it more clear.

Squeak is an interesting system. All the source code for the system is embedded in the system itself. This means that you can actually go ahead find the code where a certain feature has been implemented rather easily. And if you desire, you can even change that behavior to suit yourself. Of course, before either of that could happen, you need to know how to look for the code first. I am going to show you three methods for locating code in Squeak. As our example, we will be looking at ways to find where the "Save and Quit" functionality is implemented.

The first method requires the use of the Method Finder (or selector Browser). You can drag an instance of the Method Finder from the tools flap in Squeak. Or you can create a new instance from the World Menu. Just as its name implies, you can use the Method Finder to find methods. You just need to enter a fragment of the method name in the search box and look for it. Sometimes this requires guessing the method name. Fortunately the naming convention in Squeak is fairly consistent and most of the time your guess will help you find the method.

Finding code in Squeak - 1
Here I am guessing that there must be a method called "saveandquit" so I enter that into the Method Finder (or Selector Browser) and try to find it. The results show that there is indeed such a method and that two classes have it: TheWorldMainDockingBar and TheWorldMenu.

However, the Method Finder is useful for other things as well. It has a very cool feature that is missing in a lot of other languages. You can actually pass parameters for a method and the return value and it will list all the methods that will satisfy those constraints! You do not even need to know the name of the method. Look at the examples below:

Finding code in Squeak - 2
Here I am trying to find out if Squeak already has a method to sum up an array for me. So I enter #(1 2 3 4). (remember the dot!) as the input and 10. (remember the dot!) as the output. Sure enough, it returns that the method sum can sum a collection for me.

Finding code in Squeak - 3
Another useful example is when you cannot remember the name of a function. If you program in multiple languages, some methods might be named differently. For instance the method could be called 'toUpperCase' or 'upperCase!'. Instead of hunting for the name, just enter the input and the output and the Method Finder will spit out the proper name for you.

The second method is actually even more neat. You can usually just select the morph itself to find out what code it is implementing! This works for most of the Morphic menus. Try doing that in your normal programming language environment!

Finding code in Squeak - 4
Right-click on the World Menu. You will see the halo appear with the text "Menu" at the bottom. %>

Finding code in Squeak - 5
Right-click directly on the "save and quite text" again. It should now change to a smaller halo with the text "MenuItem" at the bottom. Click on the menu button (it is the red icon).

Finding code in Squeak - 6
Select "explore morph" from the debug submenu.

Finding code in Squeak - 7
Check out the highlighted text. It shows you the information that you were looking for. This method requires some hunting for the information because it has a lot more other information about the morph itself.

The final method is actually the most powerful but least interesting. This is just like the normal search command that you have in your IDE. It is going to search through everything for the text.

Finding code in Squeak - 8
Type the text "save and quit" into a new workspace window. Highlight it and then middle click on it. Search for the "more..." submenu right at the bottom of the menu. Another menu will pop-up. In this menu, select "method source with it". You can use the other options as well depending on your needs.

Finding code in Squeak - 9
It gives you a whole list of methods with that text in it. You will have to hunt the information that you want down but this is the most detailed way to find "everything" that is related to the text.

And those are the three methods for finding code in Squeak. The first two methods are the most useful and the final one should be used when all else fails. With these methods, you should feel be able to satisfy your curiosity and find out everything that you want to know about Squeak.

Posted in | no comments | atom

Trackbacks

Use the following link to trackback from your own site:
http://softwareengineering.vazexqi.com/trackbacks?article_id=finding-code-in-squeak&day=30&month=05&year=2007

Comments

Leave a response

Leave a comment