tuples and cartesian coordinates

Skip Montanaro skip at pobox.com
Wed Dec 17 22:37:50 CET 2003


    >> See the recent (long) thread on this subject:

    >> http://tinyurl.com/zoyt

    Gerrit> Hmm, the only message I see on the question whether tuples are
    Gerrit> useful for *coordinates* is:

Well, the thread was more general (tuples vs. lists), but if you think of
coordinates as immutable objects, then using tuples makes more sense (at
least to me).  If I have two objects, and one moves to be at the same
location as the other, this seems natural:

    o2.location = o1.location

I'd hate to see o2 suddenly move when o1 moves five clicks north:

    o1.location[1] += 5

If you use tuples, o2 stays put when o1 moves:

    o1.location = (o1.location[0], o1.location[1]+5)

(That just demonstrates that I'd assign a new coordinate tuple to
o1.location.  I would probably hide the tuple surgery in a move_relative()
method.)

Skip





More information about the Python-list mailing list