Austin Ziegler
11/4/2004 3:08:00 PM
On Thu, 4 Nov 2004 15:21:49 +0100, Michael Neumann
<mneumann@ntecs.de> wrote:
> On Thu, Nov 04, 2004 at 08:37:40AM -0500, Austin Ziegler wrote:
>> On Thu, 4 Nov 2004 12:48:14 +0100, Michael Neumann
>> <mneumann@ntecs.de> wrote:
>>> On Thu, Nov 04, 2004 at 12:13:20PM +0900, Austin Ziegler wrote:
>>>> Contraindications
>>>> -----------------
>>>> While Transaction::Simple is very useful, it has some severe
>>>> limitations that must be understood. Transaction::Simple:
>>>>
>>>> * uses Marshal. Thus, any object which cannot be Marshal-ed
>>>> cannot use Transaction::Simple.
This isn't as bad as it sounds. Most things that can't be Marshal-ed
can't be usefully snapshotted, either (e.g., IO objects).
>> Taking a quick look at your library, it looks like it does much
>> the same as mine, except it uses an external object for
>> transaction management and, obviously, doesn't use Marshal. There
>> are several
>
> Yes, because a transaction (or snapshot) might involve any number
> of objects.
Right. But this can be accomplished with Transaction::Simple using
the block mechanism added in 1.2:
Transaction::Simple.start(a, b, c) do |ta, tb, tc|
...
end
>> reasons that I implemented it this way, the most important being
>> your implementation of Array#take_snapshot: it dups the array:
>>
>> irb#1(main):001:0> arr = %w(a b c d)
>> => ["a", "b", "c", "d"]
>> irb#1(main):002:0> arr2 = arr.dup
>> => ["a", "b", "c", "d"]
>> irb#1(main):003:0> arr2[0] << "z"
>> => "az"
>> irb#1(main):004:0> arr
>> => ["az", "b", "c", "d"]
>> irb#1(main):005:0>
>
> Right! And that's for my purposes a good thing, as I register
> objects that I want to be "backtrackable" (it's more flexible this
> way).
Mmm. More flexible, but more work. When I want a transaction on an
object, I want its full state kept. This, to me, is useless:
a = %w(a b c) # 'a', 'b', 'c'
# take a snapshot
a << "d" # 'a', 'b', 'c', 'd'
a[0] << "z" # 'az', 'b', 'c', 'd'
# restore # 'az', 'b', 'c'
Simply taking snapshots of the current object references (which is
what your snapshot process does) only performs part of the necessary
behaviour for true transaction support. I actually was trying
something like this (not as formalised, certainly) with PDF::Writer
and was running into problems because my objects were changing even
when I didn't want them to change, which is why I created
Transaction::Simple.
I have not yet encountered any times when I've used T...::Simple
that the loss of __id__ is a problem. I suspect that in a stateful
environment (appservers, for example) this is more likely to be a
problem, but very little that I work with at this point is stateful.
Ideally, I'd love to see Object#__replace__ that only works on
objects of the same immediate class, replacing the internal
representation of the object but maintaining the __id__ just like
Array#replace does now. This way, I'd be relatively safe from
potential rewrites of #replace and still maintain the __id__.
-austin
--
Austin Ziegler * halostatue@gmail.com
* Alternate: austin@halostatue.ca