Collection and Stream (was: RE: [BUG] ReadStream>>isEmpty ?)

Andreas Raab andreas.raab at gmx.de
Fri Aug 8 22:13:44 UTC 2003


> (ReadStream on: #(1 2 3 4 5) from: 3 to: 3) size
> 
> Returns 3.
> 
> I have to disagree that size is properly implemented.

No, #size is perfectly well implemented. Trust me ;-) What's wrong is the
implementation of streams, the mismatch between streams and collections to
recognize the similarity of the two. For example, if we merely say that:

Stream		Collection		Meaning
-------------------------------------------------------------
readLimit		tally			Actual number of elements

Then you can see that #size (as well as #isEmpty) are perfectly well
implemented, since both are assumed to refer to the actual number of the
elements, rather than the maximum number. If we go one step further, then we
can say that:

Stream		Collection		Meaning
-------------------------------------------
writeLimit		#capacity		Maximum number of elements

Here, you may ask what the hell we'd need writeLimit for, and you'd be
perfectly right to ask. If you look at who ever assigns to writeLimit then
you'll see that is _always_ assigned the underlying fixed collections size
except for the singular case of #on:from:to:.

That may make us wonder who really needs that method so let's look at the
senders. In the image that I'm using there are about 19 senders out of which
_NONE_ uses a writable stream.

In other words: writeLimit is NEVER, NOT ONCE initialized to anything but
"collection size".

Go figure. The only conclusion I can take out of the above discussion is
that our stream hierarchy is intrinsically badly designed (and I am sure
there are more people agreeing than disagreeing on this).

> I understand that now, but I have to blame a large part of my
> misunderstanding on the fact that both the ReadStream and WriteStream
> class method on:to:from: comments use the word "copy".

Right. That's just a minor bug in the overall design problems.

> My confusion is based on the code in the image which clearly doesn't
> match any idea of size that I can come up with.

Yup, that's exactly what I meant. The code doesn't reveal that it's
essentially the same as in collections so it's left to you to figure out the
mappings I've shown above. For most people this is _really_ hard if they
have nothing but code to go by. Which only emphasises the importance of a
well-designed class library.

Hey, Craig, how's Flow going? ;-)

Cheers,
  - Andreas



More information about the Squeak-dev mailing list