Re: [flexcoders] AS3 improvement feedback

2010-06-20 Thread Oleg Sivokon
This is called type inference, it exists in several languages, C# would be
one the most popular, HaXe would be the one most close to AS.

@Rick Genter:
It depends, most probably the compiler would give you an error/warning
because of ambiguous code, and if not - would choose a common denominator
for the two classes. One thing I agree though, this will not be backward
compatible. On the other hand type inference is more then just a convenience
feature. I hadn't seen much of it's been useful, but once it helped to
resolve a very complicated situation.


Re: [flexcoders] AS3 improvement feedback

2010-06-20 Thread Alex Harui
You can get some of that by turning off strict-mode which Flex turns on by 
default, but there won’t be type checking if you do.


On 6/19/10 9:31 PM, "dorkiedorkfromdorkt...@gmail.com" 
 wrote:






Currently if you leave a variable untyped it remains untyped. So to
type something I have to include the type in the declaration like so:

var myInstance:ClassA = new ClassA();

but as you can see the type is specified in the instantiation! so I'm
thinking that by default when a variable doesn't specify a type then
it should be typed intrinsically by the compiler to the class that is
instantiating it.

So these two examples would be the same:
var myClass:ClassA = new ClassA();
var myOtherClass:ClassB = new ClassB();

var myClass = new ClassA();
var myOtherClass = new ClassB();

you'd still be able to cast it but you wouldn't have to. so the
default behavior of AS3 would be to do the best practice not the worst
practice.

jp





--
Alex Harui
Flex SDK Team
Adobe System, Inc.
http://blogs.adobe.com/aharui


Re: [flexcoders] AS3 improvement feedback

2010-06-19 Thread Rick Genter

On Jun 19, 2010, at 10:33 PM, dorkie dork from dorktown wrote:

> 
> 
> Right but the compiler is already hoisting, which means it moves all variable 
> declarations to the top of the function. For example, the following code 
> compiles even though the initial trace() function for the num variable 
> happens before the num variable is declared:
> trace(num); // NaN
> var num:Number = 10;
> trace(num); // 10
> The compiler will not, however, hoist any assignment statements. But it could 
> use the assignment statements to dynamically type the variable. So then:
> 
> var x = new A();
> 
> var x;
> x = new A();
> 
> would be the same

It can't be. What happens in this case?

var x;
if (y == 1) {
   x = new A();
} else {
   x = new B();
}

--
Rick Genter
rick.gen...@gmail.com



Re: [flexcoders] AS3 improvement feedback

2010-06-19 Thread dorkie dork from dorktown
Right but the compiler is already *hoisting*, which means it moves all
variable declarations to the top of the function. For example, the following
code compiles even though the initial trace() function for the num variable
happens before the num variable is declared:

trace(num); // NaN
var num:Number = 10;
trace(num); // 10

The compiler will not, however, hoist any assignment statements. But it
could use the assignment statements to dynamically type the variable. So
then:

var x = new A();

var x;
x = new A();

would be the same

I think for the backwards compatibility issue it could be handled with a
compiler option. more important than getting around the issues would be
would you use it?

On Sat, Jun 19, 2010 at 11:35 PM, Rick Genter  wrote:

>
>
>
> On Jun 19, 2010, at 9:31 PM, dorkie dork from dorktown wrote:
>
> > Currently if you leave a variable untyped it remains untyped. So to
> > type something I have to include the type in the declaration like so:
> >
> > var myInstance:ClassA = new ClassA();
> >
> > but as you can see the type is specified in the instantiation! so I'm
> > thinking that by default when a variable doesn't specify a type then
> > it should be typed intrinsically by the compiler to the class that is
> > instantiating it.
> >
> > So these two examples would be the same:
> > var myClass:ClassA = new ClassA();
> > var myOtherClass:ClassB = new ClassB();
> >
> > var myClass = new ClassA();
> > var myOtherClass = new ClassB();
> >
> > you'd still be able to cast it but you wouldn't have to. so the
> > default behavior of AS3 would be to do the best practice not the worst
> > practice.
> >
> > jp
>
> If you did that then you would break backwards compatibility. Also, it
> means the following two code fragments would behave differently:
>
> var x = new A();
>
> var x;
> x = new A();
>
> I think that's a bad idea.
> --
> Rick Genter
> rick.gen...@gmail.com 
>
>  
>


Re: [flexcoders] AS3 improvement feedback

2010-06-19 Thread Rick Genter

On Jun 19, 2010, at 9:31 PM, dorkie dork from dorktown wrote:

> Currently if you leave a variable untyped it remains untyped. So to
> type something I have to include the type in the declaration like so:
> 
> var myInstance:ClassA = new ClassA();
> 
> but as you can see the type is specified in the instantiation! so I'm
> thinking that by default when a variable doesn't specify a type then
> it should be typed intrinsically by the compiler to the class that is
> instantiating it.
> 
> So these two examples would be the same:
> var myClass:ClassA = new ClassA();
> var myOtherClass:ClassB = new ClassB();
> 
> var myClass = new ClassA();
> var myOtherClass = new ClassB();
> 
> you'd still be able to cast it but you wouldn't have to. so the
> default behavior of AS3 would be to do the best practice not the worst
> practice.
> 
> jp

If you did that then you would break backwards compatibility. Also, it means 
the following two code fragments would behave differently:

var x = new A();

var x;
x = new A();

I think that's a bad idea.
--
Rick Genter
rick.gen...@gmail.com



[flexcoders] AS3 improvement feedback

2010-06-19 Thread dorkie dork from dorktown
Currently if you leave a variable untyped it remains untyped. So to
type something I have to include the type in the declaration like so:

var myInstance:ClassA = new ClassA();

but as you can see the type is specified in the instantiation! so I'm
thinking that by default when a variable doesn't specify a type then
it should be typed intrinsically by the compiler to the class that is
instantiating it.

So these two examples would be the same:
var myClass:ClassA = new ClassA();
var myOtherClass:ClassB = new ClassB();

var myClass = new ClassA();
var myOtherClass = new ClassB();

you'd still be able to cast it but you wouldn't have to. so the
default behavior of AS3 would be to do the best practice not the worst
practice.

jp