Note that Sprite, and Surface are mutable, but can be used as
dictionary keys. They don't use their values as the keys.
However Rect can not be used for keys... so that's an inconsistency -
but maybe a good one. Since generally you would want to use the
values of the Rect as the keys - so it forces a conversion to tuple.
I wonder how much effort it would be to make immutable and mutable? I
think maybe too much.
overall... +1 for mutable.
cu,
On Sat, May 2, 2009 at 12:07 AM, Lorenz Quack <don@xxxxxxxxxxxxxxxxx> wrote:
Hi
as a follow up to the "API draft for vector type" I would like to discuss
the merits of having a mutable or immutable vector type.
Arguments for an immutable vector type:
Brian Fisher pointed out two advantages of immutable vector types:
1) they prevent bugs in programs like the following (adopted from Brian):
class Angel(object)
def __init__(self, offset):
self.offset = offset
t = Angel()
halo_pos = t.offset
halo_pos.y -= 5 # BUG: this changes the offset in t
2) if vectors are immutable you can use them as keys in dicts
Arguments for a mutable vector type:
1) operations such as rotate() and scale_to_length() are more elegant when
operation in-place. for immutable types you would have to do "v =
v.rotate()" or use a module level rotate function "v =
pygame.math.rotate_vector(v)" or something similar.
2) a priori I would expect mutable vectors to perform better than immutable
ones because you don't have to create new objects for every operation.
So are there anymore arguments?
And where do people stand on this issue?
yours
//Lorenz