[squeak-dev] About String vs Symbols

Eliot Miranda eliot.miranda at gmail.com
Tue Jul 29 19:38:27 UTC 2008


On Tue, Jul 29, 2008 at 9:21 AM, stephane ducasse
<stephane.ducasse at free.fr>wrote:

> Hello
>
> I'm reading newspeak spec and I like the idea of immutable strings.
> Now what does it really bring to us?


Safety.  One can no longer overwrite literals or methods (or anything else
whose state you want to protect) accidentally.

Expressive power.  One can use immutability as a write barrier in orthogonal
persistence or distribution schemes (and other things) .  One marks an
object as immutable to indicate that it is persistent or distributed and its
changes should be exported.  The immutability scheme allows one to associate
managers for specific objects that handle NoModificationErrors on a
per-object basis.  So if an object is immutable and has an appropriate
manager that manager can temporarily enable immutablity for the object,
allow the modification, communicate the modification (e.g. to a database or
remote image) and then re-enable immutability.  The framework allows an
object to have multiple managers.  (This is all standard Squeak and very
similar to the code I wrote for VW.  The VM code is also available from
Cadence).

Then does it mean that we could get rid of symbols
> immutability does not imply unique identity.


No.  As you point out Symbols are unique and so immutable strings don't
replace them.  But it is nice to have immutable Symbols.  e.g. try to do
this in your Squeak image:
    #class pvtAt: 1 put: 0 asCharacter
Scary :)


>
> Stef
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20080729/8bba16b3/attachment.htm


More information about the Squeak-dev mailing list