— Shang Liang

i, for loop, uint and int in ActionScript 3

Defining i:uint is not better than i:int since both of them take the same amount of memory. Besides, it’s risky to define i:unit because if i is accidentally assigned to a negative value it becomes a big positive int.

4 comments
  1. Keith Peters says: February 14, 20087:33 am

    I often use uints. Not because of any memory or performance reasons, but because it documents the intention of the variable. You are stating, “this variable is an integer, and should never be negative.” The problem is, like you said, when you make it negative, it flops over. I think it would be better if it threw an exception if you tried to make it negative..

  2. Derek Vadneau says: February 14, 200811:32 am
  3. Christian Cantrell says: February 14, 20082:47 pm

    I usually use uint, though I have had instances where I’ve had it become a huge positive number. I figure 4294967295 is just as big of a bug as -1, so I usually don’t worry about it.

    Christian

Submit comment

For spam filtering purposes, please copy the number 2686 to the field below: