The Weekly Squeak work page
Last updated at 6:41 am UTC on 27 February 2006
This is the work-in-progress copy of The Weekly Squeak. It will be often updated during the week and, once its content is cooked, moved to TWS' main page.
Feel free to peruse this notes, but please note that this is a work in progress whose content may vary a lot, and can contain errors and omissions. – The News Team
The Weekly Squeak, Light Edition No.2: January 8th - January 14th
An interesting (albeit long) discussion on immediate types, memory allocation, garbage collection, et al.
SqueakLight: an overview of the project
On development process, backwards compatibility and forks
A quick description of HttpView2, and plans for the future
Cryptography Repository Publicly Available
French Seaside tutorials
Google video: Squeak videos now for download
The Weekly Squeak, Light Edition No.3: January 15th - January 21st
Recent updates for Squeak 3.9 alpha, with Changelogs.
A discussion on the PlusTools: should they stay or should they go?
Let's talk about Squeak 3.8.1
Team Reports for December, 2005
The Weekly Squeak, Light Edition No.4: January 22nd - January 28th
The Weekly Squeak, Light Edition No.5: January 29th - February 4th
The Weekly Squeak, Light Edition No.6: February 5th - February 11th
The Weekly Squeak, Light Edition No.7: Februray 12th - February 18th
DrGeo II: a dynamic geometry enviroment in Squeak
The Weekly Squeak, Light Edition No.8: February 19th - February 25th
New Mac VMs, now with Unix file names
The Weekly Squeak, Light Edition No.9: February 26th - March 4th
by Ron Teitelbaum
Welcome to a new column called Squeaklings. The intention of the column is to occasionally point out interesting code snippets that may have been posted on squeak-dev or other interesting code samples that we have come across. The intended audience for this column is everyone, but we will try to focus on code that can be understood quickly by most readers.
In this episode of Squeaklings we will concentrate on the method
- BlockClosureensure: aBlock (in VW Smalltalk see valueNowOrOnUnwindDo: )
Ensure does what it says: No matter what I want you to ensure the following code block is always run.
Here is an example of how it might be used:
ďWrite the literal string 'Hello there I am your Myfile contents' to the file ĎMyFile.txtíĒ
[aFile := FileStream fileNamed: 'MyFile.txt'.
aFile nextPutAll: 'Hello there I am your Myfile contents' copy.
] ensure: [aFile close].
This seems pretty straight forward: No matter what if this code fails, I always want you to close the file. Here are some ways to test this. Add a halt in the code and see if the file closes after abandoning the halt. You can also add a halt in the ensure block to see when the code executes.
So is this code safe? Well in general it is but there are gotchas to watch out for. Your ensure block is not fail safe. In this case if aFile is nil (put a halt after FileStream and abandon the halt). A message #close sent to nil equals kabluee so be sure that what is in your ensure block can actually be run in the event of an error. If you are executing this code in a workspace be sure to add the | aFile | . I will leave it as an exercise to answer why.
One last thing you may be wondering why I added a copy onto my string literal. Iíve been told over and over this is not necessary but being bitten once by an OODB that persisted string literals and blew things up because of it, I always put it in. Try this. Add a method test to any class that returns a string literal.
MyClass class test
Then execute the following code MyClass test at: 2 put: $a. Now what does MyClass test return? Look at the method, look at the result. Itís true in general that this is very unlikely to happen, unless you use the OODB Iím talking about but it feels better to me to add the copy which fixes this problem.
Comments, requests etc.
Any comment, request, threat or flame should be sent to theNews Team.