Why we should remove {} from Squeak

Andrew C. Greenberg werdna at mucow.com
Wed Oct 3 17:39:52 UTC 2001


>> * As I said in my first reply to Stephane, I don't mind having an 
>> object
>> that's created at compile time, so long as it's immutable (because its
>> semantics then make its history and time of creation irrelevant). So
>> Booleans, Blocks (to be precise, closures, if they were), Characters,
>> Integers and Floats are okay. Arrays and Strings I expect to be 
>> mutable,
>> so they are not ok.
>
> Actually, blocks, characters, large integers, and floats are all mutable
> in Squeak, too.  It's just not a problem because people know better than
> to modify these things.

Interestingly, my first serious inexplicable coding bug as a Smalltalk 
beginner was precisely that problem.  I wrote a bit of code that had a 
method to "initialize" a string, and then processed it in other 
methods.  Something along the lines of:


startMeUp

	dataString := 'initial value'


doMe

	"process, manipulating dataString accordingly"

Of course, this works fine the first time, but failed thereafter, 
because the string object in startMeUp was itself changed and thus no 
"initalizations" occurred after the first one.  The only way to assure 
the correct semantics was to clone or copy the constant.  It took me 
forever to understand why startMeUp was failing.

I have since learned to refactor out smelly stuff such as that, but hey, 
live and learn.





More information about the Squeak-dev mailing list