i, for loop, uint and int in ActionScript 3
Thursday 14 February 2008 - Filed under Tips
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.
2008-02-14 » 5566

14 February 2008 @ 7: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..
14 February 2008 @ 11:32 am
For a bit more detail on the subject, check out these entries:
http://www.bit-101.com/blog/?p=908 (surprised kp didn’t mention it)
http://tracethis.com/archives/2007/02/14/as3-tip-for-loop-index-should-not-be-uint/
http://kuwamoto.org/2006/06/15/avoid-ints-in-actionscript/
14 February 2008 @ 2: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