EndOfStream unused
Matthew Fulmer
tapplek at gmail.com
Wed Nov 7 03:59:44 UTC 2007
On Tue, Nov 06, 2007 at 11:05:58PM +0100, nicolas cellier wrote:
> EndOfStream Exception seems to be unused in 3.10
>
> My understanding was that:
>
> [[aStream next doSomething] repeat]
> on: EndOfStream do: [:exc | exc return: nil].
>
> would be more efficient than testing atEnd at each loop:
> (would only the EndOfStream be signalled!)
>
> [aStream atEnd]
> whileFalse: [aStream next doSomething].
as an aside, Exception handling isn't really squeaky, in that it
is hardly used at all in most code. More commonly used is stuff
like custom control structures:
Dictionary>>at:ifAbsent:
Dictionary>>at:ifPresent:
Object>>ifNil:
You could define this in ReadStream, ReadWriteStream, and maybe
RWTextOrBinaryStream to cover most cases:
nextIfAtEnd: aBlock
"Primitive. Answer the next object in the Stream represented by the
receiver. Fail if the collection of this stream is not an Array or a String.
Fail if the stream is positioned at its end, or if the position is out of
bounds in the collection. Optional. See Object documentation
whatIsAPrimitive."
<primitive: 65>
position >= readLimit
ifTrue: [^ aBlock value]
ifFalse: [^collection at: (position := position + 1)]
> Am I all wrong?
> What do you think?
Just a guess, but blocks are pretty fast, probably faster than
exception handling, and, imho, a lot simpler. Exceptions are
more feature complete, but not commonly needed, imho. And, you
could do "nextIfAtEnd: [EndOfStream signal]" to do error
handling.
--
Matthew Fulmer -- http://mtfulmer.wordpress.com/
Help improve Squeak Documentation: http://wiki.squeak.org/squeak/808
More information about the Squeak-dev
mailing list
|