[squeak-dev] (ReadWriteStream on: #(1)) next ... nil?
Levente Uzonyi
leves at caesar.elte.hu
Mon Jul 5 21:06:20 UTC 2021
Hi Marcel,
On Mon, 5 Jul 2021, Marcel Taeumel wrote:
> Hi all!
>
> Does anybody know whether it would be dangerous to set the readLimit when initializing a ReadWriteStream? PositionableStream does this. WriteStream overrides this explicitely. ReadWriteStream is a WriteStream.
>
> Example:
> (ReadWriteStream on: #(1)) next
>
> I am asking because our most famous R/W stream is RWBinaryOrTextStream. :-)
Changing #on: is dangerous because it might affect the behavior of
existing programs. Tracking down a "bug" like that could be rather hard.
You may want to use #on:from:to: to create your stream, which initializes
the instance the way you expect it:
(ReadWriteStream on: #(1) from: 1 to: 1) next "==> 1"
#on: behaves as #on: collection from: 1 to: 0.
Levente
P.S.: just noticed that ReadWriteStream has a fairly bad #hash method
which breaks when you send #contents to the stream. It would be nice to
check whether that #hash method is actually in use.
P.P.S.: Most subclasses of ReadStream and WriteStream are flawed in some
way. They should be subclesses of Stream and be able to operate on
another stream. ReadStream and WriteStream are misnomers. They are
streams operating on an internal collection, not generic read/write
streams you should subclass for your use case.
More information about the Squeak-dev
mailing list
|