[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[pygame] When to use a constant
- To: pygame-users@seul.org
- Subject: [pygame] When to use a constant
- From: Jon Doda <jdoda@sympatico.ca>
- Date: Tue, 11 May 2004 10:02:41 -0400
- Delivered-to: archiver@seul.org
- Delivered-to: pygame-users-outgoing@seul.org
- Delivered-to: pygame-users@seul.org
- Delivery-date: Tue, 11 May 2004 10:01:18 -0400
- Reply-to: pygame-users@seul.org
- Sender: owner-pygame-users@seul.org
- User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.6) Gecko/20040117
I'm working on a simple 2D physical simulation. The various simulation
objects have position and velocity attributes that store the x and y
components in a list. So, to get the y component of velocity for some
object you do something like "sim_object.velocity[1]".
Recently I've been tempted to define constants for the index values of
the lists, so I'd have X = 0, and Y = 1, and the code from above would
be "sim_object.velocity[Y]". It would make reading the simulation code
somewhat easier (no more converting 0 to x and y to 1 in my head) but it
would add a level of indirection, which could be confusing.
So, the question is, would using constants in this way be a reasonable
thing to do, or is it bad practice?
--
Jon Doda