Strongly typed arrays — coming to ActionScript near you
I’ve been wanting to have strongly typed arrays in ActionScript for a long time. I was pretty excited when I read that it’s part of the EcmaScript 4th edition specification (in the form of the Vector class), and much more excited when I heard that the Vector class is being included in Flash Player “Astro” (as announced at 360 Flex Atlanta by Matt Chotin).
Since the majority of the time when someone’s using an Array in ActionScript, they really want all the elements to be the same type anyway, this is a really great addition and I think it will be used heavily. The Vector class allows (requires) you to specify the type it will contain at compile time — both for variable declarations and when creating instances. In both cases the syntax you use is a “type parameter” suffix .<T>:
var names:Vector.<String> = new Vector.<String>();
The type parameter syntax is part of a separate EcmaScript 4th edition proposal. Sadly they couldn’t make the syntax identical to that for generics in C# (and I believe Java does it the same way), which is almost the same but without the initial . (period). (For an interesting read, take a look at the history of the various options the committee members considered for representing type parameters.)
Anyway, because you specify the type at compile time, the idea is that the compiler can do the type checking for you for adding and getting elements from a Vector instance. In addition, since using Array (and the runtime type checking and type casting that array access involves) has always been a bottleneck in ActionScript performance, I expect that performance improvements can be expected. (Okay, I’ve heard anecdotal reports around the office of much better performance for Vector than for Array.)
Francis Cheng (who’s on the EcmaScript committee) has a couple of nice articles about the Vector class and type parameters, so I won’t bother recreating everything he’s written. Definitely worth a read (like everything he writes).
As an (almost) final note, I should point out that I haven’t seen anything indicating that type parameters will be generally available in “Astro” — just Matt’s announcement about the Vector class specifically.
And finally, on a personal note, I’m excited because I get to do the documentation for the Vector class. It’s always fun getting to write about new features that are personally valuable. And this is one that I’ve definitely been interested in for a while!
You can leave a comment, or trackback from your own site.
6 Comments so far
Add your comment
Comment notes
Please keep comments on topic. Comments that are inappropriate or offensive will be edited or removed.
Paragraphs and line breaks are automatically converted to HTML, and quotation marks are converted to “smart” quotes.
The following XHTML tags can be used: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> . All others will be removed.
March 31st, 2008 at 1:12 am
Maz is reported to have said:
Have you heard any date for Astro? Adobe has been very vague on this so far, but there are so much features long waited for in that one!
{Maz}
April 1st, 2008 at 10:45 am
Paul is reported to have said:
@Maz:
Since I’m an Adobe employee, I’m afraid I can’t give any more information than what’s publicly available (which, from what I’ve seen, is almost nothing).
Honestly, I don’t even know what the official release date is — and from what I’ve seen in the past, there are probably few people who do — although we obviously have some general ideas about the timeline for the development cycle.
The best places to watch for information are:
- Justin Everett-Church
- Emmy Huang
- The Astro page on Adobe Labs
Justin and Emmy are the product managers for Flash Player. The labs page is self-explanatory. Sorry I can’t give you more/better information!
April 2nd, 2008 at 2:56 am
Maz is reported to have said:
No pb ! thanks for your clarification.
{Maz}
April 15th, 2008 at 2:53 pm
n-kawai Weblog is reported to have said:
July 26th, 2008 at 5:16 pm
Polish Adobe Flex User Group » Blog Archive » Adobe Flash CS4 is reported to have said:
[…] ponieważ dała możliwość pracy z ActionScript’em w wersji 3. Pojawić mają się za to typowane tablice ( Vector ) - które występują w standardzie ECMAScript na którym bazuje […]
October 8th, 2008 at 12:43 pm
Re: [Flashcoders] AS3 additions/changes in CS4? is reported to have said: