Very strange bug on Streams and probably compiler

Bert Freudenberg bert at freudenbergs.de
Wed Feb 14 16:10:27 UTC 2007


On Feb 14, 2007, at 16:56 , stephane ducasse wrote:

> Bert
>
>> It is normal.
>
> No this is not. You get used to it and accept it.
>>
>> You are modifying the 'a test ' literal into 'to test'. This  
>> modified string gets copied in the second test.
>>
>> Lesson: never modify string literals.
>
> It shows that the fact that the compiler optimizes the use of  
> certain literals such as boolean and number is good
> for immutable objects but is wrong for mutable object such as strings.
>
> Iin the semantics of Smalltalk nothing says that two strings with  
> the same representation in the same
> methods are pointing to the same object. I did not check in which  
> books but the difference between strings and symbols
> is really that two strings are pointing to two different objects,  
> while symbols are referring to the same objects (and are immutable).

The sharing is not the primary problem, the mutability is.

- Bert -





More information about the Squeak-dev mailing list