So we all know people build some amazing things using ActionScript: it’s a flexible language that provides some syntactic sugar to make developer’s lives easier. That sugar, however, gives me, umm, toothaches, some of which I talked about already. So now, I’ll rant about some other idiosyncrasies of AS3 that make it an interesting language to build tools around.
Vectors:
With Flash Player 10 comes a new “language construct” called Vectors. Vectors, like the rest of the language goodies in ActionScript come from the ECMA standards body. More specifically, it came from the ill-fated ES4 specification that has been scraped due to infighting, politics and other artifacts of design-by-committee. I’ll side-step the politics here, and just say that Vector is an interesting idea. It adds type-safe collections to ActionScript, and it provides a pretty dramatic speed increase since it side-steps things like type-checking. But Vector does not provide a generic typing mechanism like you would find in C++ or Java, arguably reducing Vectors usefulness. That’s also why I put “language construct” in quotes: it’s more like a performance optimization exposed to the user. Anyway…
The syntax is pretty interesting though:
Vector.<Vector.<Boolean>>();
var myVector:Vector.<String> = new Vector.<String>;
var anotherVector:Vector.<Vector.<Boolean>> = new
The initial delimiter is .< and it’s actually not ambiguous at all. If we just used the < operator, it would conflict with E4X which already conflicts with the less than operator. But, we do come across another problem: how do you close a Vector? Well, with a > which also happens to conflict with E4X and conflict with the greater than operator. But wait, there’s more! We also conflict with >>, >>> and >>>=. Insurmountable? No. Annoying? Yes.
Thing that makes me grumpy #2- Context sensitive keywords
Alright, this one is fun. So ActionScript has a set of reserved words that we’re all painfully familiar with: if, then, else, while, for, do, class, interface, function, var, const, etc. They’re just artifacts of the language, and you can’t use them as identifier names. Tons of other programming languages follow this model, not just ActionScript. But where AS differs from most is the use of context-sensitive keywords. These include get, set and namespace. They’re reserved works in one context, but in another they can be used as identifiers. So…
public function get myVar():String {
return “HelloWorld”;
}
public function get():String {
return “HelloWorld”;
}
So when is get a keyword? Only when it’s followed by the function keyword. Fun, right? Same thing for set, and then namespace is a different issue entirely. We need it for E4X. In Flex Builder and in asc, we need to be smart enough to know when a keyword is reserved, and when it’s actually an insane context-sensitive artifact that makes my head hurt.
Ok, that’s it. Tomorrow (or in the next couple days) I’ll go over my other favorite piece of AS3: hoisting…


How about this as an alternative:
var myVector:Vector.^String^ = new Vector.^String^;
var anotherVector:Vector.^Vector.^Boolean^^ = new Vector.^Vector.^Boolean^^();
Same problem: it’s an operator
A similar issue comes up when you try to name any part of your packages with reserved words… like those poor folks at Icelandic Air:
import is.icelandic.myClass
that will fail because “is” is a keyword. It’d be nice if, by context, AS would know when is is a keyword or not–insert reference to Bill Clinton
I’m a big fan of AS3, waiting for your Part 3
This is very interesting.
Seems you made a good progress for FB4, so get() will be available in the auto-complete dropdown?
Yep, that should work correctly
Still no part 3?
Sorry, just got back from vacation. I’ll get a post up this week