[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[pygame] When to use a constant



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