Is it right to use a private constant in the following situation:
Say I have a game with a lives variable and a startingLives variable. At the start of the game I set the lives variable to equal the startingLives variable. This is how I would normally do it:
private var lives:int = 0;
private var startingLives:int = 3;
private function startGame():void
{
lives = startingLives;
}
(example code is ActionScript btw)
My question is - should this really be:
private var lives:int = 0;
private const STARTING_LIVES:int = 3;
private function startGame():void
{
lives = STARTING_LIVES;
}
StartingLives seems unlikely to change at runtime, so should I use a const, and change back to a variable if it turns out not to be constant?
UPDATE: The consensus seems to be that this is a good use of a constant, but what about amdfan's suggestion that you may want to load the value in from a config file?