[squeak-dev] Immutability (was Re: About String vs Symbols)
Janko Mivšek
janko.mivsek at eranova.si
Tue Jul 29 22:24:59 UTC 2008
Eliot Miranda wrote:
> > Wouldn't that break a lot of code? Like anything that does
> WriteStream
> > on a String like #streamContents: ?
> >
> No, unless you're doing WriteStream on: '' which you should not do
> anyway.
> Normal Strings (those that are created with #new: or with copying) are
> mutable, just as they are now.
> In general, any code that breaks when the immutability of literals is
> ensured by the VM was broken to begin with...
>
>
> +1.
>
> Its trivial to fix such code. e.g. if you have
> (ReadWriteStream with: 'The date is ') print: Date today; contents
> you simply change it to
> (ReadWriteStream with: 'The date is ' copy) print: Date today;
> contents
> and you're done.
>
> Some developers in the VW community complained when we introduced
> immutability in 2002 about exactly these cases. But the fuss soon died
> down as people realised that indeed their code was safer with the change.
I can confirm that. Changes to the existing code due to the immutability
were indeed rare. In my case mostly changing WriteStrean on: '' to
WriteStream on: String new.
Best regards
JAnko
--
Janko Mivšek
AIDA/Web
Smalltalk Web Application Server
http://www.aidaweb.si
More information about the Squeak-dev
mailing list
|