Problems with ActionScript, Part 3
Monday, July 30th, 2007Maybe it’s just me, but I think most programmers would agree: some languages are just more beautiful than others. Beautiful is of course a relative term, but many programmers would probably agree it’s due to some complement between structure and simplicity. From a personal standpoint, I find Java to be well-structured, yet still beautiful. I also find Ruby to be simple from a verbosity point of view, which probably attributes to its beauty.
ActionScript looks very similar to Java. In fact, almost exactly like Java. I would probably compare it more closely to C#, but apples to apples, am I right? Either way, there is something inherently bad looking about it…something we all hate to love. It looks a lot like JavaScript. Here’s some examples:
public var myVar:String = "My string";
public function myFunction(o:Object):int{}
What irks me is that with a few changes the language would look just like Java/C#, providing two benefits: No unnecessary syntax and ease of learning for developers who already know those languages. Let’s pick apart the examples.
In the first example there’s two problems. For one, what is the point of specifying “var”? It seems pretty obvious to me that we’re creating a variable as there’s no syntax for parameters or a function block, so we’re definitely not creating a function or class. You might say they are trying to keep consistency with declarations, but with a variable, we aren’t defining structure, we’re defining an instance of something that has already been defined. Why not change the syntax to something a bit more understandable in my opinion:
public String myStr = "My string";
We’ve simplified the ActionScript code greatly. For one, it is more obvious that this object is a string. We’ve also removed the whole var nonsense. By mixing the variable name with its type, it makes for a little bit harder to read code: “myStr:String”. It’s hard to explain, but it seems unnatural to me to say: “I’m creating a variable named myStr. It is a String. It has this value.” It may look fine at its surface, but as a programmer, I would prefer to start generic and get into more details as I go: “I have a String. Its name is myStr. Its value is ‘My string’.”
Let’s tackle the second line of code. It has the same problems as the first essentially. What is the point of saying “function”? If it is to keep the pattern of stating what things are when defining their structure (Classes, packages, etc.), then I’ll allow it. Again, I would prefer to switch the entire function prototype around to something like this:
public int myFunction(Object o) {}
We’ve removed the unnecessary function declaration and also made it more clear what this function returns, as well as what types it accepts as its parameters. Why do I like having the return declaration to the left of the function name as opposed to the right? Well, let’s think logically and apply how we generally call functions. When you call a function, you tend to set its returning value to a variable, and just like in math and most programming languages using infix notation you have the variable on the left side and equation on the write. We can think of a function as the equation being solved and the result being stored on the left side of the equation. It just seems natural.
Maybe it’s just me, maybe I’m just picky about the look of my code. Ask Chris, I’ll have a fit if people put their curly braces on the next line after a function declaration, or if they don’t use curly braces after block statements that contain only one line of code after it, or if they don’t comment. Will Adobe ever change ActionScript to look more like how I’d like? Probably not. But this post goes out to those who find ActionScript a bit unnatural.
Well, that’s it for the roast of ActionScript. I could post about how it has no collections framework, but that’s outside the scope of the language in my opinion. Overall, ActionScript 3.0 is an improvement over its older versions (Except for the removal of private constructors), and it will only lead to more powerful Flash applications. Of which, we hope to show you in the near future.