Monthly Archives: October 2007

Discover ECMAScript 4: The Future of ActionScript

Update: Since I wrote this article, some interesting news has surfaced. New information about this topic is available in my articles Some controversy over ECMAScript 4 and How will ECMAScript “Harmony” affect ActionScript 3.

The ECMAScript working group recently released a (PDF) work-in-progress overview of ECMAScript 4. What is ECMAScript? According to the official website, the working group calls it “the language of the web”. More specifically, it’s the basis for languages such as JavaScript and Flash’s own ActionScript.

The official release of ES4 won’t happen until Fall 2008, but the working group releases updates from time to time to keep us informed (or salivating, depending on your level of geekiness). Adobe, a member of the working group, used an earlier draft of ES4 as the basis for AS3, and they’re “publically committed to sticking to [the ES4] standard” (source). The current update to ES4 includes many changes that we will probably see in a future revision to Flash’s programming language. I read the entire document from beginning to end, and I wanted to share some of my favorite discoveries.

Core Classes

Object and Array have picked up some new friends. In particular, a class called Map works a lot like Object, but it allows you to use any value as a key (not just a String). This is very similar to flash.utils.Dictionary in AS3, but there’s one interesting addition that I’ll get to in a moment. Similar to Array, there’s a new class named Vector. Of note, it provides bounds checking, and you can optionally specify a fixed length. Using a new language feature, both Map and Vector are parameterized types. Vector is actually what some might consider a typed Array. When you create an instance, you must specify the datatype of the objects you intend to place inside the Vector. Similarly, to use Map, you must specify both the key datatype and the value datatype. An example borrowed from the PDF overview should help illustrate how these will work:

//create a Map with keys of type * (known as any type) and values of type int
var example1:Map = new Map.;

//create a Vector to contain integers
var example2:Vector = new Vector;

Language Features

Some of the coolest additions to ES4, in my opinion, are record types and the like keyword. Think of record types as ultra-light classes. They define members, but aren’t an entire class definition. Here’s an example of a record type:

type Point = { x:Number, y:Number };

It should be no surprise that you can create new instances of these types (you’ll get a regular Object, though) like any class.

var myPoint:Object = new Point();

What’s more interesting is that you can use the like keyword with record types to produce some interesting results. In AS3, a MovieClip has x and y properties that are both instances of class Number. This makes a MovieClip like the Point type described above (don’t confuse it with flash.geom.Point).

var clip:MovieClip = new MovieClip();
clip like Point //true

Imagine being able to run a function on any object that has x and y properties without requiring a special interface or setting a parameter’s type to Object (where you’d have to do runtime checks to ensure that x and y even exist!).

Another useful class-like feature is something called a union type. To understand union types, think of a current feature of AS3: Number, uint, and int are all pretty much interchangeable. That’s because ES4 defines an internal union type AnyNumber to accept and convert all numeric values as needed (notice a few new numeric types, by the way).

type AnyNumber = (byte,int,uint,double,decimal,Number);

The new let keyword gives us a more familiar block scoping mode used by other languages. In the current incarnation of AS3, a variable in a function is always accessible from anywhere in that function, by using let instead of var, you can make a variable that is only in the scope of a for-loop or an if statement. Excellent.

A feature I see requested often is operator overloading. Thankfully, this will be made possible thanks to another new feature generic functions. These functions are outside of classes and they’re pretty close to the bare metal of the runtime. Here’s an example:

generic intrinsic function + ( a:String, b:MyCustomString )
{
    //some operation that concats a MyCustomString with a regular String
}

The docs say that you cannot override a generic operator that has been implemented already, but you can add new ones that support your own custom classes. I’m sure some folks might complain, but I’d say it’s good enough for me. I’d hate to see the messes some dumb developer could create if he changed the way the core types behave with operators.

Finally, I’d like to share iterators. Two new types, IterableType and IteratorType give you the ability to code your classes to work with for-in and for-each-in loops more easily. Previously, in AS3, developers could only iterate over dynamic properties with these loop types. Now, by implementing a couple methods, get() and next() you can give a little more power to your applications, but only if needed. Older AVM1-era Flash applications could always iterate over properties, but today, that’s been removed for a performance boost. Nice to see this feature come back, if a developer chooses to use it.

That certainly isn’t everything new that we’ll see coming in the final version of ES4. I just picked out a few particular things that caught my eye and seemed the coolest. Be sure to read the ECMAScript 4 Overview PDF for full details.

Just as I was “impatiently waiting for ActionScript 3” back in the alpha days, you can bet that I’m just as excited for the next version today. Too bad it could be years away! When? Who knows. I’d say I’m pretty safe guessing that Flash Player 10 is out of the question. Adobe has their hands full with the features they’ve shared already. Furthermore, they would be silly to introduce major language revisions in two consecutive player versions. I’m also still seeing many learning the migration path from AS2, and I don’t think that dangerous sea will calm for a while. Definitely FP11 at the earliest, and after the ES4 spec has been finalized. In other words, be patient, but smile and dream of the cool coding tricks you’ll be able to do someday.

An Open Letter to Silicon Valley Recruiters

Dear Recruiter,

It looks like you’re helping a hot new client that needs talented developers yesterday. That’s great! Get out there and find the best of the best! I should warn you about something, though. When you want to contact me about the next “YouTube meets Salesforce meets The Next Big Thing™” startup, I may be a little difficult to deal with. It can be boiled down to the fact that I, like many developers, simply don’t like talking to recruiters. We just want to talk tech and write great code, and a recruiter isn’t always the person with the information we need. Adding a middleman to any process sucks. Let me give you some guidelines for keeping things running smoothly when dealing with a stubborn developer like me.

  1. Get to the point. I actually don’t particularly care who’s funding your startup. Investors don’t impress me. Buzzwords force me to read between the lines, so try leave those out as best you can. Honestly, I mostly care about what sort of cool projects I’ll get to work on and if I’ll be able to face interesting challenges. Tell me that you want a Flash or Flex developer, and give me some details about what I could be working on to actually get my attention. Informing me that some company is “the hottest new video startup” doesn’t help me because half the new startups out there call themselves “the hottest new video startup”. I shouldn’t need to ask, “what do they do with video?” In short, if you can’t tell me about the awesome products or services I’ll be able to help build, I’m not interested.

  2. I have contact me links all over my blog. That’s the best means of sending me a message if I don’t know you. I set it up mainly for folks that want to send me questions about my open source projects or blog content, but it’s great for contacting me about anything else too. Messages sent from the contact page go directly to my email inbox. In fact, I’ll admit that I like getting email that isn’t from the zillion mailing lists to which I’m subscribed. Send me something there, and I’ll probably read it. The only recruiter that’s ever gotten me to change jobs started the conversation by sending me a message through my contact page.

  3. LinkedIn messages are okay too. However, I’m unlikely to add you as a connection, even if I send you a response. If I added every recruiter that contacted me, I’d have expanded my network to a useless eighteen billion people that I don’t know very well. My LinkedIn connections are almost always people I’ve worked with or met at professional developer community events. Unless you’ve had a drink with me and talked tech, you’re probably not getting on that list.

  4. Facebook messages are never okay. My profile on Facebook is for personal friends only. Your message will never get a reply on Facebook. Guaranteed.

  5. Are you an employee of the company you recruit for? That’s better than if you work for some third-party recruiting company, in my eyes. Many recruiters don’t necessarily have enough information to interest me, and if you work for the company in question, you’ll be able to put me in contact much more easily with a person who has real answers. If you only have a basic job description, do you really expect me to go out of my way to learn more? I’m already happy with my current employer, so if I’m faced with too many steps to get from a recruiter to useful information, there’s no point in trying.

  6. I’m a Flash and Flex developer. My resume has been known to list a few other technologies I’ve been capable of using, but I believe that I’ve made it extremely obvious that I dig the Adobe Flash Platform above all else. Don’t contact me about your company that wants to build AJAX RIAs. While I am proficient with some JavaScript libraries like jQuery or YUI, I’m not going to drop Flash any time soon. Definitely don’t contact me about server-side development because that’s never going to happen. I’m a front-end, client-side developer.

  7. Do you prefer to contact me by phone? Please don’t. You’re interrupting me while I’m working, and you’re using up my precious time. I will do everything in my power to say, “thank you, but I’m not interested” as soon as possible. With email, I can read your sales pitch whenever I want, but the phone requires me to put everything aside specifically for you, yet another random recruiter. If you must insist on calling me, please see the following suggestions:

    • Don’t call me at work. Do you really think I want to say, “Sure, I’d love to work somewhere else!” when my manager sits nearby? Even giving you my email address (or a better time to call) feels impolite to my current employer. Why put me in a negative situation? It will only hurt your efforts. On a related note, calling the front desk of the company I work for to get my number only impressed me once. I thought the guy was being resourceful. Then I realized that apparently every recruiter does that. Thanks for wasting my employer’s resources too.

    • Don’t leave a voicemail if I’m not here. I’ve had phones that won’t let me delete messages until they’re finished playing. As you can probably probably imagine, I’m going to zone out once I hear, “Hi Josh, I’m a recruiter from [insert some recruiting company]“. I’ll read email or something while I wait for you to finish droning on and on about the boring life stories of your startup’s founders and investors.

    • Don’t ask me for additional contact information over the phone. The spelling of my email address seems to be difficult to understand sometimes. You got my phone number already with your dark recruiter magicks. I’ll bet you can find my email address too. Of course, for best results, consider using my contact page.

In conclusion, Mister or Miss Recruiter, please keep the interruptions of my day to a minimum, get to the point as quickly as possible, and try give me the juicy details. I promise I’m not actually that difficult to deal with. All I ask is that you have respect for my time and needs as an innovative technologist. If you have a job or contract that seems fascinating and stimulating, I’ll happily listen.