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?