[Q] Newbie - Multiple Return Values

Cees de Groot cg at cdegroot.com
Thu May 1 15:07:46 UTC 2003


On Thu, 2003-05-01 at 16:23, Donald Major wrote:
> The easiest solution is to just return an Array or some other 
> collection, made up on the fly, containing your two (or more) return 
> values. Works great. :-)
> 
Depends on what you understand as 'works'. Personally, if I see
something like:

result := foo doSomething.
(bar := result at: 1) > 0
   ifTrue: [self error: (result at: 3)]
   ifFalse: [^result at: 2]

all refactoring alarms go off. That's assembly programming, has about as
much relation with object orientation as Windows with security. 

Really, encapsulating the result in a class is much nicer, especially
because you can then start converting 'tell' methods into 'ask' methods
(don't "give me foo" but "please do bar with whatever you represent").
There's about zero overhead (probably exactly zero - whether you
construct an Array instance with two or three members or a FooResult
instance with two or three instance vars does not matter).

Basically, Array et al. are fine for encapsulating stuff within objects,
they're almost never fine for transmitting state between objects if the
Array contents aren't strictly homogeneous (i.e. an array of bytes is
ok, an array that is a struct in disguise - first element a string,
second one a boolean, ... - is an absolute no-no).


-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
Url : http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20030501/2b42384d/attachment.pgp


More information about the Squeak-dev mailing list