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

Re: [pygame] When to use a constant



I would make velocity a class with x and y components, so that the code would
be:

sim_object.velocity.y

I'm not saying this is the best way to do it, however. I'm interested to see
what other people would do.

--- Jon Doda <jdoda@sympatico.ca> wrote:
> 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



	
		
__________________________________
Do you Yahoo!?
Win a $20,000 Career Makeover at Yahoo! HotJobs  
http://hotjobs.sweepstakes.yahoo.com/careermakeover