[Cuis-dev] String vs Symbol objects

Gerald Klix cuis.01 at klix.ch
Tue Jul 30 13:07:07 PDT 2024


+1 from me. I just started to write an e-mail with the same suggestion ...

I was bitten too many times by global dictionaries in Python
and global strings back in 1987 with Smalltalk/V to not
be strongly in favor of this suggestion.


Best Regards,

Gerald



On 7/17/24 6:05 PM, Nicolas Cellier via Cuis-dev wrote:
> Juan, the vm has support for immutability for quite some time, so it might
> be time to use it for literals.
>
> Le mer. 17 juil. 2024, 19:01, Juan Vuletich via Cuis-dev <
> cuis-dev at lists.cuis.st> a écrit :
>
>> On 7/17/2024 12:43 PM, Mark Volkmann via Cuis-dev wrote:
>>
>> Interesting! In this code I create two equivalent String objects, then
>> modify a character in one of them. I wondered if it would do a "copy on
>> write", but it did not. The modification affected both which was surprising
>> to me.
>>
>> str1 := 'test'.
>> str2 := 'test'.
>> str1 at: 1 put: $b.
>>
>> In this case, str1 and str2 refer to the same object in memory, so both
>> now have the value "best".
>>
>> I suppose the lesson is that literal strings in the same scope might
>> (always?) use the same object in memory.
>>
>>
>> The other lesson, at least to me, is that String mutation is bad (and
>> ugly). It is generally better to create them anew, in a more functional
>> style.
>>
>>
>> On Wed, Jul 17, 2024 at 10:12 AM Juan Vuletich <juan at cuis.st> wrote:
>>
>>> On 7/17/2024 11:08 AM, Mark Volkmann via Cuis-dev wrote:
>>>
>>> When I enter the following lines in a Workspace, select them, and "Do
>>> it", I get an AssertionFailure error:
>>>
>>> str1 := 'test'.
>>> str2 := 'test'.
>>> self assert: str1 ~~ str2.
>>>
>>> Ken, are you saying that you do not get that error?
>>>
>>> --
>>> R. Mark Volkmann
>>> Object Computing, Inc.
>>>
>>>
>>> Side comment: an AssertionFailure is an Exception but not an Error (see
>>> class hierarchy).
>>>
>>> You get the AssertionFailure if you select all three lines and evaluate
>>> them together, but not if you evaluate them one by one.
>>>
>>> Truth is that str1 and str2 can not be assumed to be the same object. But
>>> they can not be assumed to be different object either. The compiler is free
>>> to reuse the string if it is easy enough.
>>>
>>> Cheers,
>>>
>>> --
>>> Juan Vuletichcuis.stgithub.com/jvuletichresearchgate.net/profile/Juan-Vuletichindependent.academia.edu/JuanVuletichpatents.justia.com/inventor/juan-manuel-vuletichlinkedin.com/in/juan-vuletich-75611b3twitter.com/JuanVuletich
>>>
>>>
>> --
>> R. Mark Volkmann
>> Object Computing, Inc.
>>
>>
>>
>> --
>> Juan Vuletichcuis.stgithub.com/jvuletichresearchgate.net/profile/Juan-Vuletichindependent.academia.edu/JuanVuletichpatents.justia.com/inventor/juan-manuel-vuletichlinkedin.com/in/juan-vuletich-75611b3twitter.com/JuanVuletich
>>
>> --
>> Cuis-dev mailing list
>> Cuis-dev at lists.cuis.st
>> https://lists.cuis.st/mailman/listinfo/cuis-dev
>>
>



More information about the Cuis-dev mailing list