I use the shelve module every now and then, and by default shelve
requires specific assignment to the key to cause persistence.
As such:
# Copy in memory
temp = obj.db.test
temp[2] = 4
# persist to disk
obj.db.test = temp
Is more natural to me in the python world. In other code, which is
mainly JavaScript, all persistence (what little of it there is on the
client side) is explicit, and unless noted I'm dealing memory only.
The PackedList is a cool idea, but I see it useful from a Builder
perspective, not necessarily an implementor (coder) perspective.
Builders, who are usually quite creative and smart but aren't always
coders in "real life" might have use of something like the PackedList
exposed in their code. A cave-in happens in a room that we want to be
permanent and immediately written to disk. Always good to not throw
the baby out with the bathwater, unless the baby is named Damien or
Regan or TheBadSeed ;)
- Jeremy
On Feb 23, 7:18 am, Griatch Art <
gria...@gmail.com> wrote:
> In the dev blog Such a Small Thing<
http://evennia.blogspot.com/2012/02/such-small-thing.html>,
> I outline some of the underlying difficulting with implementing easy-to-use
> Attributes. There is however a side effect of this that is not mentioned,
> and which leads to what may not behave as you would expect.
>
> Consider the following situation:
>
> obj.db.test = [1,2,3,4]
>
> This saves the list to an attribute 'test'.
>
> test = obj.db.test
>
> This retrieves the stored list - but it is not a list anymore! It's a
> PackedList, an object that saves every change to itself to the database. So
> type(test)==list will fail.
> The reason for making it such is to allow for the in-sity assignment of
> data, like obj.db.test[2] = val (further nesting than that doesn't work).
>
> Anyway, assume that we, with our newly fetched variable, we now do
>
> test[2] = 4
>
> You are updating the list as expected, *but you are also right away saving
> it to the database, because this is what PackedLists do. *This is not at
> all intuitive and might even be very confusing if you expect to be working
> on a normal list away from the database. Using test = list(test) will
> convert it to a "normal" list, but who will remember to do this?.
>
> Dictionaries have the same behaviour, returning a PackedDict.
>
> So my question to those reading this list is this:
>
> *Is the ability to do e.g. obj.db.test[2] = 1 worth the tradeoff of getting
> PackedDicts/PackedList's back from Attributes? *