Archive for the 'Programming' Category

07 December 2007 > Squeak Image Updated

Just a quick notification that I updated my squeak image (several of you have asked).

It’s based on Damien Cassou’s latest Squeak Dev Image (Squeak 3.9), an awesome base image with all the necessary goodies a developer needs. Of course I’ve loaded up my window customizations and preferences, nicer looking fonts, and have all the preferences set the way I like.

Nothing major in this update other than keeping up with the latest versions of everything I use. I have removed the SentorsaBrowser and TrickRefractoringBrowser because the new OmniBrowser is just getting too good to use anything else. Enjoy.

Seaside 2.8 Released

Quoted from the Seaside mailing list…

After a beta phase of two months we release the final version of Seaside 2.8. Most bugs fixed during this period were either long standing (already in 2.7), minor or portability related, Together with the dozens of Seaside 2.8 applications already in production today this gives a pretty good feeling about this version. A special mention deserves Roger Whitney, thanks to him we went from 99 commented classes to 144.

We have a list of new features [1] and a migration guide [2] on our homepage.

Squeak users can get it either from SqueakMap, Universes or directly via Monticello (Seaside2.8a1-lr.518). A special note for Squeak users, do not load Seaside 2.8 into an image that has already Seaside 2.7 in it. If you use Squeak 3.7 you will have to load SeasideSqueak37 as well.

VisualWorks users can get it form Store (2.8a1-lr.518,tkogan).

GemStone/S users can load Seaside2.8g1-dkh.522.

[1] http://www.seaside.st/community/development/seaside28a1
[2] http://www.seaside.st/documentation/migration

Cheers
The Seaside Team

I’ve been using 2.8 for a while now in development and for several weeks in production, it’s solid and very easy to port to for 2.7 users. Upgrade as soon as you can, it’s quite a bit snappier and uses much less memory.

Smalltalk Concurrency, Playing With Futures

Concurrency is always a source of problems in complex systems and one of the coolest patterns I’ve seen for simplifying it is Futures. I thought I’d explore the idea today and hack up a quick implementation of a dynamic Future proxy.

The basic idea is to take a block of code, schedule it on another thread and return a dynamic proxy that if accessed, blocks until the value returns. This lets useful work continue on the main thread until you access the value.

A nice way to break up a big task concurrently might be to #collect: all the futures for a bunch of work processes you have, say fetching rates for a bunch of hotels that require calls to outside systems that may or may not return quickly, and then aggregate the results at the end.

Here’s the complete implementation, it’s quite simple but seems to work pretty well while playing around in a workspace and makes concurrency seem less of a beast.

First the class, a subclass of ProtoObject since we’re building a proxy…

ProtoObject subclass: #SFuture
	instanceVariableNames: 'futureValue error lock'
	classVariableNames: ''
	poolDictionaries: ''
	category: 'OnSmalltalk'

Then a #value: write accessor which eagerly kicks off the process, sets up, and clears the lock after fetching the future value.

value: aBlock
    lock := Semaphore new.
    [futureValue := [aBlock on: Error do: [:err | error := err]]
                ensure:
                    [lock signal.
                    lock := nil]] fork

Now a #value read accessor that blocks if the lock still exists, re-throws any error that may have happened on the worker thread in the context of the main thread, and finally returns the future value.

value
	lock ifNotNil: [lock wait].
	error ifNotNil:
			[error
				privHandlerContext: thisContext;
				signal].
	^ futureValue

A quick testing method for checking if the future has finished executing (useful for doing what work you can with the results that have returned).

hasValue
	^lock isNil

And the all important #doesNotUnderstand: override that intercepts any message sent to the proxy and sends it to the future value, causing the thread to block until the result is finished computing.

doesNotUnderstand: aMessage
    ^ self value
		perform: aMessage selector
		withArguments: aMessage arguments

Finally, a single extension method to BlockContext to make using the future more natural and ensuring to call fixTemps so I can collect future values in a loop with the assumption that the block will act like a proper closure.

BlockContext>>future
	^ SFuture new value: self fixTemps

Now we can ask any block for its future value and just pretend we have it. Executing some test code in a workspace…

value1 := [200 timesRepeat:[Transcript show: '.']. 6] future.
value2 := [200 timesRepeat:[Transcript show: '+']. 6] future.
Transcript show: ‘other work’.
Transcript show: (value1 + value2).

Reveals the string ‘other work’, a long string of interspersed periods and pluses, and finally 12, the result of adding the value returned by each future. In all, a pretty nice way to handle concurrency, I’ll have to see where I can simplify some code with the use of Futures, I can already think of a few.

20 October 2007 > Squeak Image Updated

Just a quick notification that I updated my squeak image a few days ago, I’m just getting around to posting about it.

It’s based on Damien Cassou’s Squeak Dev Image (Squeak 3.9), an awesome base image with all the necessary goodies a developer needs. Of course I’ve loaded up my window customizations and preferences, nicer looking fonts, and have all the preferences set the way I like. The main update here is Squeaks great new UI enhancements from Gary Chambers and Seaside 2.8. Squeak has never looked better, I hope to see the UI enhancements continue to make Squeak a tool for grown ups.

« Previous PageNext Page »