Array does return *, regardless of what the docs say.  The best test,
IMHO, is assignment...downcasting an Object type requires a cast, while
downcasting a * type doesn't.  For example:

 

Var o:Object = new Foo();

Var s:* = new Foo();

 

Var f1: Foo;

 

f1 = o; // error...need a cast

S = o // legal...no compile time type checking.

 

Regarding performance...I haven't run tests, but I'd be surprised if
there's a big difference.  The performance gains come from doing a
static field lookup that can be resolved at verification time, vs. a
dynamic field lookup that  needs to be resolved at runtime.  Other than
the 2 or 3 properties/methods defined on object, all field/property
lookups will be dynamic and done at runtime. i.e.:

 

o.doSomething(); // dynamic lookup;

s.doSomething(); // dynamic lookup;

f1.doSomething(); // static lookup.

 

Ely.

 

 

From: [email protected] [mailto:[EMAIL PROTECTED] On
Behalf Of Troy Gilbert
Sent: Thursday, May 24, 2007 11:09 AM
To: [email protected]
Subject: Re: [flexcoders] star (*) data type vs. Object

 

Hmm... don't dictionaries and array effectively return something of type
* ?

In the case of pop(), etc., it wouldn't make sense for the array to
return * because that would mean it _could_ return the value of
undefined, which doesn't make sense. As Gordon points out, Object is
stronger in that it at least indicates existence, even if it is null. 

In the case of [ ], isn't the array and dictionary actually returning
something of * type? I know the docs say it's "Object", but it _can_
return undefined, which by definition means it can't be of type "Object"
(undefined has no type). 

I'm curious as to the performance implications... I've seen repeated
several times in the docs and blogs that using the strong typing creates
faster code... and I believe it coming from a C++ background where
static types (as opposed to virtual types) are faster because the
compiler can remove some indirection. 

But in AS3, and in particular the AVM2, is there similar indirection
being created by the compiler in the bytecode for dynamic types that
doesn't get generated for static types? Gordon, can you speak to what
the bytecode difference is between dynamically typed code and statically
typed code? 

Troy.



On 5/23/07, Johannes Nel <[EMAIL PROTECTED]> wrote:

good post and i agree, dictionaries and arrays should return *

On 5/23/07, Derek Vadneau < [EMAIL PROTECTED]
<mailto:[EMAIL PROTECTED]>  > wrote:

        "* is just like Object"
        
        I couldn't disagree more.
        
        I really dislike that Object is referred to in the docs about *.
There is an implication there that they are similar when they really
aren't. 
        
        This is a sore spot for me everytime I use Array.pop() and
Array.shift() in the Flash IDE. Both of those functions have their
returns typed as Object. Why? Someone thought it was a good idea because
you can have any type returned ... Well, no. Yes, you can have any type
returned at runtime, but you can't actually type the return variable to
anything except Object or nothing. 
        
        For example, the Array.as file in the Flash 8 Classes folder
defines:
        function shift():Object;
        
        If you try to do this you will get a compiler error: 
        
        var arr:Array = new Array(3); 
        var n:Number = arr.shift(); << compiler error
        
        
        The same holds true in AS3. For example:
        
        function go():Object
        {
        return 'something';
        }
        
        Everything's valid here. Setting the return type to Object
allows me to return any type that subclasses Object, which is
everything. 
        
        var s:String = go(); << compiler error
        
        "Implicit coercion of a value with static type Object to a
possibly unrelated type String."
        
        The compiler doesn't swing that way!
        
        So Object and * are NOT interchangeable. And the difference
isn't subtle. 
        
        Use Object when you want to actually use generic objects and *
when you want to dynamically-type something.
        
        
        

        On 5/18/07, Peter Farland < [EMAIL PROTECTED]> wrote:

        See:
        
        http://livedocs.adobe.com/flex/2/langref/specialTypes.html#*
        
        The type * is just like Object but it can also store values that
are
        undefined. Object can only store null.
        
        It's useful to determine whether a dynamic property actually
exists on a
        type and just happens to be null, or whether it literally is not
defined
        on that type.
        
        ________________________________
        
        From: [email protected]
<mailto:flexcoders%40yahoogroups.com>  [mailto: 
[email protected] <mailto:flexcoders%40yahoogroups.com> ] On
        Behalf Of Adam Pasztory
        Sent: Friday, May 18, 2007 2:42 PM
        To: flexcoders
        Subject: [flexcoders] star (*) data type vs. Object
        
        Can anyone tell me what the difference is between setting a
generic
        variable's data type to Object and setting it to *. Are they
        equivalent? 
        
        I tried to search for the answer, but it's hard to do a search
for *. :)
        
        thanks,
        Adam

        
        
        
        -- 
        
        Derek Vadneau 




-- 
j:pn 
http://www.lennel.org

 

 

<<image001.jpg>>

<<image002.jpg>>

Reply via email to