views:

142

answers:

2

I've got a class that is essentially mutable, but allows for some "persistent-like" operations. For example, I can mutate the object like this (in Python):

# create an object with y equal to 3 and z equal to "foobar"
x = MyDataStructure(y = 3, z = "foobar") 
x.y = 4

However, in lieu of doing things this way, there are a couple of methods that instead make a copy and then mutate it:

x = MyDataStructure(y=3, z="foobar")
# a is just like x, but with y equal to 4.
a = x.using(y = 4)

This is making a duplicate of x with different values. Apparently, this doesn't meet the definition of partially persistent given by wikipedia.

So what would you call a class like this? QuasiPersistentObject? PersistableObject? SortOfPersistentObject? Better yet, are there any technical names for this?

+2  A: 

I call this kind of data Persistable but not sure if it's a word .

ZZ Coder
That's the first word that came to my mind too, but it seemed a little bit made up to me as well. :-)
Jason Baker
Persistable is a totally cromulent word, no matter what my browser's dictionary tells me. Not only is it cromulent, but also quite performant. My dictionary just needs to be embiggened...
ifatree
+2  A: 

It's just a optimized copy, I'd rather rename the operation to reflect that.

a = x.copy_with(y=4)
THC4k
I like the way in which types in the datetime standard library module express this concept -- they name the method `replace` (of course, they ARE immutable types, so it should be clear they return a tweaked copy rather than mutate the original;-).
Alex Martelli
That's another way to do it. I had kind of intended for this to have a fluent interface. It reads like english: "x using y equal to 4".
Jason Baker