Sockets and finalisation
Brent Vukmer
bvukmer at blackboard.com
Thu Jan 22 22:13:29 UTC 2004
>
> On Jan 22, 2004, at 1:42 PM, Andreas Raab wrote:
> > Therefore, if you write an app which uses
> resource-allocating objects,
> > it is
> > YOUR task to make sure they are closed properly. Which is
> one of the
> > reasons
> > why patterns such as:
> > file := self openFile: 'foo.txt'
> > [self doSomethingWith: file] ensure:[file close].
> > are used. IOW, the above ensures that the opened file is indeed
> > properly
> > closed after we are finished with it, finalization or not.
>
> 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
>
> This is quite common in other languages that make heavy use of
> closures, ie Lisp (with-file 'foo' (f) ...) and Ruby
> (File.open('foo'){|f|...}), but for some reason it doesn't seem to be
> idiomatic in Smalltalk.
>
> Avi
>
>
Couldn't resist submitting this, Avi. Coolness.
More information about the Squeak-dev
mailing list
|