On Mar 7, 2007, at 23:45 , Lex Spoon wrote:
"Lukas Renggli" renggli@gmail.com writes:
Also, FWIW, if you like the ANSI version, it is easy to implement. Here is a version using a dead forked dialect of Squeak; it should be easy to dust it off should anyone want. This version goes further than discussed in this thread, and even makes floats and large integers be immutable. :) The code is in islands.zip on the following page; look inside the zip for immutLits1.5.cs and immutLits2.2.cs.
In 3.8 and 3.9 there are 5 subclasses of String (Symbol, Byte and Wide) and many more for ArrayedCollection. Your change would introduce many read-only classes and lead to much duplicated code (ok, traits would be a big help here).
Immutability should be an instance-level property and not special class.
Good point, there was just one String back then so it was simpler.
What Andreas was saying (IIUC) is that the abstract String class provides default implementations for all String functions that use a very small number of "kernel" methods that are declared subclass- responsibility. That means all the rest of the code in the String subclasses is just an optimization, so adding a new subclass should be straight-forward.
This of course assumes that people actually honor that design and not bypass it by adding functionality to String subclasses directly.
- Bert -