View this PageEdit this Page (locked)Attachments to this PageHistory of this PageHomeRecent ChangesSearch the SwikiHelp Guide
Hotspots: Admin Pages | Turn-in Site |
Current Links: Cases Final Project Summer 2007

Squeak Tips / FAQ

Here is some useful information we discovered while developing our projects and while taking the class. We hope you can find them useful.

Q: If there was one or two pieces of practical information about how to write programs in the squeak environment (note: not the language), what would it be?

Q: HELP! I have an infinite loop! How do I break it?

Q: What is the equivalent squeak code for the java statement System.out.println("Hello, world!")?

Q: Can you tell me about a useful squeak feature that is not common in most other languages?

Q: I have a static class variable. It seems to be maintaining its value/contents across executions of my program. Why is this?

Q: I need to add a button to a parent morph but I need it to pass arguments to its handler. I can't seem to figure out a way to do this with PluggableButtonMorph. How can this be done?

Q: If there was one or two pieces of practical information about how to write programs in the squeak environment (note: not the language), what would it be?

A: Save often. Our team found that while the squeak language itself was very interesting to code in, the practice of writing programs inside of the virtual machine itself is somewhat cumbersome. Saving ("filing out") your work often can prevent costly recoveries of work from the changes file; or save your work altogether if the changes file becomes corrupted (we're speaking from experience here!). Also, learning about change sets and projects can be very beneficial to your teams productivity and integration efforts.
Infinite loops or infinite recursion happens to even the best programmer. Unlike other compiled languages or other environments where the source is external from the virtual machine (i.e., Java), killing the squeak VM (as opposed to killing the Java VM or a running executable) can wreak havoc on your work by corrupting the changes file and your squeak environment. One thing that no one told us before we started is that ALT-. is equivalent to the behavior of CTRL-C in other environments to break execution.

Q: HELP! I have an infinite loop! How do I break it?

A: ALT-. (ALT + the period key).

Q: What is the equivalent squeak code for the java statement
System.out.println("Hello, world!");
?

A:
Transcript show: 'Hello, world!' ; cr.
But you also have to open up a transcript to see the result.

Q: Can you tell me about a useful squeak feature that is not common in most other languages?

A: Yes. We found that blocks were very useful and indispensible in writing our project. Blocks are an execution unit of squeak code that can be generated at any time and then executed with supplied values. For this project, we used them to do queries on the sets of people we were storing genealogical information on. Here is a simple block example:

| b |
b := [:x|Transcript show: x printString; cr.].
1 to: 10 do: [
  :i|
  b value: i.
].


Q: I have a static class variable. It seems to be maintaining its value/contents across executions of my program. Why is this?

A: You need to have a statement that at the start of your "program" that clears the value of the static variable. Since squeak never resets its execution state, the value of static class variables can persist.

Q: I need to add a button to a parent morph but I need it to pass arguments to its handler. I can't seem to figure out a way to do this with PluggableButtonMorph. How can this be done?

A: Take a look at SimpleButtonMorph. Here is some example code from our project. Note the use of an OrderedCollection to hold the arguments and how the presence of any and all :'s are necessary to tell squeak that your action selector accepts arguments.

| component |
component := SimpleButtonMorph new
	label: person getMother getName ; 
	target: toNotify ; 
	actionSelector: #handlePersonChange: ; 
	arguments: (OrderedCollection with: person getMother) ; 
	borderWidth: 2.
self addMorph: component frame: (0.2@y extent: 0.2@0.1).


Link to this Page