[squeak-dev] Immutability, what it is, why
Janko Mivšek
janko.mivsek at eranova.si
Wed Jul 30 15:53:49 UTC 2008
Dear Squeakers,
A bit explanation of immutability will help you understand what it is
good for and why it is good to be introduced in Squeak.
1. immutable object = read only object. That means you can read it
but not write/change its state. Where is this good for?
2. Literals should be immutable by default. Like 'this is a literal
string'. Most of debate so far were about such immutable objects.
3. But the immutability become really powerful for persistence
support. That is, as transparent persistence as possible, without any
special commands for storing objects into a database. How can this be
achieved with immutability?
4. With a clever trick: object to be saved into a database
(persistent object) is declared as immutable. When we try to change it,
an exception occurs. In exception handler we temporary declare object as
read/write, allow the change then declare object back to immutable. We
also put that object into a set of changed or so called 'dirty' objects.
All we need to do now is to save them to a database during a commit.
5. That's how the Gemstone persistency is implemented completely
transparently on VisualWorks, which supports immutability for a while.
6. Consider how transparent can become Magma with immutability in
Squeak!
7. Consider many other uses when you need to detect object change.
We can for instance implement logging of changes into a file and
reverting in case of image crash, just as we are doing now with the code
changes.
In any case introduction of immutability opens us many new
opportunities, which outnumber the small performance penalty it introduces.
Best regards
Janko
--
Janko Mivšek
AIDA/Web
Smalltalk Web Application Server
http://www.aidaweb.si
More information about the Squeak-dev
mailing list
|