tuples and cartesian coordinates

Dave Brueck dave at pythonapocrypha.com
Wed Dec 17 15:58:00 EST 2003


Gerrit wrote:
> the FAQ says:
>
> > For example, a Cartesian coordinate is appropriately represented as a
> > tuple of two or three numbers.
>
> I find it strange to use tuples for a coordinate. After all, a
> coordinate represents a position of an object. Suppose I have a game
> where the player has a position: isn't it stupid to use tuples rather
> than lists or another type (maybe complex numbers?), because I want to
> be able to change the position?
>
> Shouldn't coordinates be mutable?

I _guess_ you could consider a coordinate to be a distinct entity. By moving
you're not changing that entity, simply referring to a new one. So if your
position were instead the name of the country the player is in, then by moving
you wouldn't mutate (edit) the name of the country but would instead reference
a different name.

Hmm... this explanation might be a bit of a stretch, but that's what popped
into my mind at least.

The counter-argument would include (among other things), that it's wasteful to
have to create a new tuple just to move the player. The
counter-counter-argument is that the tuple vs list entry in the FAQ is one of
those guidelinish things, and principles and guidelines are always the first to
go when you get bit by the optimization bug. :)

-Dave






More information about the Python-list mailing list