Why we should remove {} from Squeak
Alan Knight
knight at acm.org
Wed Oct 3 14:01:27 UTC 2001
At 06:54 PM 10/3/2001 +1200, Richard A. O'Keefe wrote:
<snip>
>This is the old "REAL oopy methods never return more than one result"
>religion again, and I for one don't believe it.
<snip>
>In Smalltalk, I have a choice of
>
>(a) tree2 := tree1 splitBefore aBlock.
>(b) aPair := tree1 splitBefore aBlock.
> tree1 := aPair first.
> tree2 := aPair second.
>(c) anArray := tree1 splitBefore aBlock.
> tree1 := anArray first.
> tree2 := anArray second.
There's another alternative, although it's one that we often don't think of
as equivalent to multiple return. (Got this idea from Anthony Lander, who
recently presented it at the Ottawa ST User Group)
(d) tree splitInto: [:tree1 :tree2 |
Do stuffWith tree1 and: tree2].
This nicely gives you named things for the results, is concise, and can
even let you avoid the potential need for an if statement to test for empty
trees. It's not multiple return, but it turns out to be a pattern that
works for an awful lot of the cases where you might use multiple return.
You've gotta love closures.
--
Alan Knight [|], Cincom Smalltalk Development
knight at acm.org
aknight at cincom.com
http://www.cincom.com/scripts/smalltalk.exe/downloads/index.asp
More information about the Squeak-dev
mailing list
|