views:

8

answers:

1

I used to write programs in the android sdk for google phone. One of the android developers guide that I read says that it is more efficient to declare a const

public static const NO:String = "no"; 

var1 == NO;
var2 = NO;

than to do this

var1=="no";     
var2="no";

For Java, when you write "no" each time, a new variable is created with the value "no" stored in it so it is more memory efficient to declare the constant. I am wondering if that is the case for action script and php as well? I am maintaining action script and php programs at work and saw a lot of strings declaration like the "no" above being used.

I am wondering if it will be worth my time to refactor these code when i have to fix the programs. I plan to leave the programs that I do not have to fix as is. Any advice or insights would be great.

A: 

ActionScript uses a string pool (containing every constant found at compile time exactly once) and to my knowledge, the strings are actually the very same object. If not, they do all point at the same character sequence. AS3 can do this, since strings are immutable.

Please note however access of static members however is the slowest way to access values in ActionScript 3.

I don't know about PHP though.

greetz
back2dos

back2dos
thank you for the answer. It looks like such refactoring are not worth the time. I should concentrate more on code that runs a lot and relies on network or database or expensive calculation/algorithm. cheers :).