ncellier at ifrance.com
Wed Nov 7 04:46:08 UTC 2007
Yes, only 129 senders of signal, 95 of signal: in 3.10, some in tests.
Exception allSubclasses size. 73, some unused.
There were no Exception in st-80...
Block is very convenient for my simple task. I like it.
But would introduce a rewrite of a lot more methods if applied to files
(see the *FileStream basicNext and all this mess).
And Exception is more general. It can be handled in various ways.
As for efficiency, passing some extra arguments at each loop might also
be less efficient than performing an Exception once at end if stream is
...as illustrated by Andreas like bench:
data := (1 to: 100000) asArray.
[1 to: 5 do:[:i|
stream := streamClass on: data.
atEnd := false.
[stream nextIfAtEnd: [atEnd := true]. atEnd] whileFalse.
971 instead of 260 for stream next == nil, and 255 for EndOfStream
Matthew Fulmer a écrit :
> 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:
> 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
> <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
More information about the Squeak-dev