Sockets and finalisation
Timothy Rowledge
tim at sumeru.stanford.edu
Fri Jan 23 04:33:33 UTC 2004
On Jan 22, 2004, at 1:59 PM, Avi Bryant wrote:
> Just out of curiosity - given this, why does FileStream not have
> methods something like
>
> FileStream class>>fileNamed: fileName do: aBlock
> |file|
> file := self fileNamed: fileName.
> [aBlock value: file] ensure: file close
>
Others have pointed to some of the problems with this when opening the
file goes wrong; I'd add that there should be a check for that before
the block is evaluated, possibly with an exception being raised. That
would make it important to consider what response the exception might
elicit so that we could continue cleanly if appropriate.
Another problem was alluded to in the swamp of methods needed to mirror
all the FileStream creation methods. My response would be along the
lines of "don't do that". Instead, factor it out better. Keep the
FileStream creation separate and make the block handling an instance
method:-
myFile := FileStream newFileNamed:'wibble').
myFile ifNil:[FileStream newFileCreationException raise].
myFile doBlock:[:fl|
fl nextPutAll: war and peace' asBook entireContents.
fl thingy].
Or something a bit like that. I don't like the name #doBlock: but I
can't think of anything better right now. #do: and #perform: are almost
right but have rather specific meanings already.
Just a thought.
tim
More information about the Squeak-dev
mailing list
|