Hi Damien,
I understand your argument and the fresh light that you've thrown on it.
BTW "having a side effect" is not what happens, after all you *want* the streamer to write, isn't it so. And in your "myStream nextPutAll: 'abcd' copy" the #copy is superflous (has no effect).
But anyways, lets not argue about the thread title.
For sure I do like consistency and friends like coherence.
My concern is that #become: would be a gun instead of using a pigeon transporting a peace message (so to speak).
So, what's your solution? Perhaps, like we have heard from the VW folks, should the streamer be adapted to *also* work on an OrderedCollection (which automagically grows). So that people can expect that, if they pass anOrderedCollection, all is fine with its contents and identity (i.e. because of the behavior which is already in OrderedCollection).
/Klaus
On Thu, 15 Feb 2007 09:14:50 +0100, Damien Cassou wrote:
Hi Klaus,
Klaus D. Witzel wrote:
I really don't want to depend on the implementation. And in my opinion, this is not encapsulated because this is MY String, not a String created internally.
Not really. If you pass a boxed object (other than a SmallInteger) the recipient can #become: it to anything he/she likes. This is reality.
I'm not talking about security, only unconsistent side effect.
Klaus D. Witzel wrote:
What I see is that the String I give to the new Stream is modified. Then at a moment, the String does not reflect the stream anymore. This doesn't sound coherent to me.
It is not coherent because you passed an explicitly written *constant* which, in other languages, is believed to be immutable.
And if you all agree to the current behavior, then a documentation should be written: "Don't use the collection after having created a stream on it !"
Easier: don't pass constant collections to the streamers :)
It's not about constant collections at all here.
myCollection := String new: 3. myStream := WriteStream on: myCollection. myStream nextPutAll: 'abcd' copy.
Here, myCollection is left untouched which sounds normal (it's still an empty string of size 3). Now, lets replace #nextPutAll: by 4 #nextPut:
myCollection := String new: 3. myStream := WriteStream on: myCollection. myStream nextPut: $a; nextPut: $b; nextPut: $c; nextPut: $d.
This should have exactly the same behavior... however myCollection now equals 'abc' !!! Why the first 3 characters ? Why not everything or nothing at all ? This is why I think it's not coherent.
I've read the source code and I understand why it happens but I don't think it's coherent. And this as nothing to do with literals nor with immutability. This is a completely different problem (this is why I changed the thread title).