Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use or not to use the with statement in AS3?

So I've been reading a lot today about the with statement performance, readability and stuff like that but i'm still not sure whether i should or should not use the with statement in AS3.

Using the with statement seems the same as creating local var which would carry the reference. Can someone provide detailed information on this topic?

like image 593
Rihards Avatar asked Dec 18 '25 01:12

Rihards


1 Answers

Well, from my own personal benchmarks the with() statement actually showed up to be a tad bit slower. This isn't a big deal unless you are trying to squeeze every last ounce of performance out of your movie. The same could be said for doing for loops against variables instead of constants, or while loops vs for loops. Unless you are compounding these loops in lots of iterations you don't really need to be concerned with it.

As for code readability, I think it makes for a cleaner look using with(). It all comes down to coding style. The only time I really use the with() statement is with say an known target. Lets say you have your mouse event handler selecting objects on click, and setting it as currentObject. You then can have a function that does something like

with(currentObject)
{
 x = 100;
 y = 100;
 alpha = 0.5;
}

Sure you could do it other ways, but like I said. It comes down to coding style. The only savings I really see by using this method is shortened keystrokes vs doing currentObject.x = 100; currentObject.y = 100;

like image 111
superfro Avatar answered Dec 19 '25 16:12

superfro



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!