I think using const for local variables that don't change is a good idea. I 
wish we had done it throughout the framework. In the future, it might allow the 
ActionScript compiler to do better optimization.

Gordon Smith
Adobe Flex SDK Team

From: flexcoders@yahoogroups.com [mailto:flexcod...@yahoogroups.com] On Behalf 
Of Florian
Sent: Friday, August 20, 2010 1:24 AM
To: flexcoders@yahoogroups.com
Subject: [flexcoders] Re: Aspects of functional programming in ActionScript



Well, the question was more intended to case like:

function elementAddhandler(event:ElementExistenceEvent):void
{
const renderer:IVisualElement = event.renderer;
}

or

function iterateOverList(list:IList):void
{
if (!list) return;

const length:int = list.length;

for (var i:int; i < length; i++) { trace(list.getItemAt(i)); }
}

I'm looking for reasons not to use constants in this context.

--- In flexcoders@yahoogroups.com<mailto:flexcoders%40yahoogroups.com>, Oleg 
Sivokon <olegsivo...@...> wrote:
>
> Despite this whole FP issue coming back into fashion in the last years,
> there's really no use for that in ECMAScript-like languages. Every piece of
> code you can write using nested functions can be rewritten in a way that no
> nested functions will be used and the program will work better.
> I'm not sure where would you need immutable objects, except date and string.
> I'm not sure what kind of impact you were afraid of re' constants, but, sure
> the constant which is not static is initialized as many times as it's scope
> is initialized:
>
> function foo():void {
> const bar:int = 100;
> }
>
> bar initialized as many times as often you call foo().
>
> class Foo {
> private const bar:int = 100;
> }
>
> bar is initialized as many times as often you create new Foo.
>
> If you need an example of intensive use of "closures" in AS3, look into
> binding mechanism in Flex. It uses them a lot, and this is why it is bad.
> Another example - Googlemaps, which is just another example of a lame code.
> It is confusing to think that big corporation with many years of programming
> experience would produce crappy code. I cannot tell why did this happen
> exactly... but you know, lots of girls wear high heels, even though it's one
> hell uncomfortable :)
>

Reply via email to