[Pharo-users] Streams for FileReference in Pharo 7

ducasse stepharo at netcourrier.com
Mon Feb 18 10:29:52 EST 2019


Hi sven

what I do not really with asString is that it potentially created another stream.
with << the implementation of camillo (if I remember correctly) manages correctly both 
single object and collection and it is nice to have. I do not know if his implementation
does not create additional stream.

Stef


> On 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 ?
> 
> Sven
> 
>> On 15 Feb 2019, at 09:52, Jan Blizničenko <jan.bliznicenko at fit.cvut.cz> wrote:
>> 
>> Hello everyone
>> 
>> I am trying to use Pharo 7 for my project and I noticed that most of my
>> streams related code does not work anymore. Reason is that API for streams
>> received from writeStream of FileReference changed and I think it changed
>> for the worse in my case, because << does not properly handle any other
>> objects than strings anymore.
>> 
>> In both Pharo 6 and 7 I can write
>> String streamContents: [ :s | s << 'hello' << 42 << $! ].
>> and get 'hello42!'.
>> I can write in Pharo 6 but cannot in Pharo 7
>> 'hello.txt' asFileReference writeStreamDo: [ :s | s << 'hello' << 42 << $! ]
>> In Pharo 6, I get same result in both examples (written to the file in
>> second case of course), but in Pharo 7, the second example results in
>> exception because << does not work with anything other than strings, so it
>> seems I have to manually convert everything to strings.
>> 
>> This change to streams seems to me like a setback for 2 reasons:
>> 1) API amongst streams is no longer consistent in this case
>> 2) streams for files lost useful functionality and to make my project
>> compatible with Pharo 7, I have to make lots of effort to make my code
>> uglier and longer
>> 
>> I would like to ask for the reason of this change and whether is there
>> anything that can be done with it. Or do I just misuse or misunderstand
>> anything? Thank you.
>> 
>> Best regards,
>> Jan
>> 
>> 
>> 
>> --
>> Sent from: http://forum.world.st/Pharo-Smalltalk-Users-f1310670.html
>> 
> 
> 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.pharo.org/pipermail/pharo-users_lists.pharo.org/attachments/20190218/8cb3cd2e/attachment-0001.html>


More information about the Pharo-users mailing list