« April 2005 | Main | June 2005 »

May 27, 2005

[Rant] Class vs Instance Names Dilemma

Just wondering how many other people suffer from my same dilemma.

Lately when building applications I end up fighting with myself over what to name the class and what to name its' instances! For example, SoundManager class; ok I guess I could call the instance soundManager but then I'm relying on case sensitivity which is something that is undesirable.

Seriously, I think I spend more time debating about names of classes / instances then I do coding them!

friday-rant =)

-erik

Posted by erikbianchi at 10:17 PM | Comments (25)

May 03, 2005

[Flash Quirks] Beware of Automatic Octal Number Conversions

When does 21 equal 17? When using Flash to convert numbers with a leading 0!

Apparently Flash will automagically convert strings starting with a leading 0 to octal numbers (base 8). However this isn't specifically mentioned in Flash's documentation for Number conversions (that I could find anyway) but is probably an ecma standard.

To see fer yerself:

var index="021";
trace(Number(index)); // output 17

It comes to this result by multiplying each value by 8: ((8*0)+1) + (8*2) = 17

To compensate for this conversation I wrote a normalize to integer function that subsequently ignores any leading zeros:

// normalize to integer
function normalizeInt(value:String):Number{
while(value.charAt(0) == "0"){
value = value.substring(1,value.length);
}

return Number(value);
}

var index = normalizeInt("021");
trace(index);


Just something to keep in mind should you ever have a spec (as I did) that required a fixed length integer that could start with a 0. =)

-erik

Posted by erikbianchi at 01:38 AM | Comments (24)