[Pharo-users] Streams for FileReference in Pharo 7

Alistair Grant akgrant0710 at gmail.com
Sat Feb 16 08:35:02 EST 2019


Hi Sven & Jan,

On Fri, 15 Feb 2019 at 10:25, Sven Van Caekenberghe <sven at stfx.eu> wrote:
>
> Hi Jan,
>
> I like #<< too, but I think your assumption that it can print anything on a stream is generally wrong, dangerous and unreliable.
>
> IMHO, you better stick to #print: in that case.
>
> Consider the follow, that all fail:
>
> String streamContents: [ :s | s << 'hello' << 42.5 << $! ].
>
> String streamContents: [ :s | s << 'hello' << (1 at 2) << $! ].
>
> In other words: #<< works in bizar ways (check the implementors of #putOn:).
>
> I would be inclined to change
>
> ZnEncodedStream>>#<< collection
>         ^ self nextPutAll: collection
>
> to
>
> ZnEncodedStream>>#<< collection
>         ^ self nextPutAll: collection asString
>
> but it would technically not be the same as the original #<< for in-memory streams.
>
> Opinions ?

I've often thought that this change would be nice to have.  #putOn:
doesn't really fit in with writing to text streams (text in the loose
sense of "something that will be read").

I think an argument could be made that #printString or #displayString
should be used, but they both have their own issues in practice.
So...

+1 to "collection asString".

Cheers,
Alistair



More information about the Pharo-users mailing list