I have a problem going backwards. When I learned attachMovie in Flash 5, that function was the death knell for my Director career. “Create something from nothing!?!?” :: queue Quake sound :: “GODLIKE!!! (nsfw)“.
In Director, everything you wanted to be on a depth had to have had something there originally, put there on the “score” (Director’s timeline). If you didn’t do this at author-time, you couldn’t swap things out on that depth. The attachMovie function in Flash was great because this didn’t matter; I had thousands of depths to play with; the sky was the limit!
I later learned the sky on _root had a limit; it was called the Settings Panel. Lakitu wouldn’t even go near that elevation. It didn’t matter though; creating new MovieClip’s allowed millions of depths that designers & coders never used; it was wonderful.
To be fair, you could abstract this stuff in Director. The crew over at Director-Online had at least 2 sprite engines that emulated what Flash did, with extra features. Furthermore, I couldn’t really appreciate this stuff back then anyway; I couldn’t even return values from functions. I just had functions set global variables. Class? Que? n00b.
I tried going back after I learned some things, but I just couldn’t do it. Flash offered too much. It was soo fast. So much more effective. ActionScript just seemed more organized than Lingo.
After getting over my frustration at AS1, I learned that I could create re-usable stuff. While I loved to re-invent the wheel ALL THE FRIKIN’ TIME, it did get tiring after awhile, especially when my 4th generation Scrollbar still lacked track clicking and scroll buttons. Creating re-usable tools was hot.
After getting over my furious frustration with AS2, and learning enough design patterns to pretend like I knew what I was doing, I slowly developed a loathing for AS1. I then had a hatred for anything not AS1; aka, code puked on frames.
I remember seeing a lot of creative things done with prototype in ActionScript 1, however, and even some still in AS2. So, I tried to go back, and experiment. I always ended up getting bit in the arse in the end.
When AS3 came out, the early version, it actually wasn’t that different (for me) from AS2. AddChild vs. createNewMovieClip, aka the new DisplayList was pretty easy. Protected vs. private, and other namespace features made sense pretty quickly too. The only hard thing was learning the immensely large new API. It’s one thing to remember that a CheckBox emits both a click AND a change event in the Flex SDK, and you need to care about the latter… it’s another to remember that navigateToURL is in the flash.utils.* package. Even the built-in stuff is immensely large.
What is interesting, though, is that I never developed a hatred for AS2. Because of the complete and utter lack of communication between the 2 AVM’s, combined with Flex’ slow rise to power meant a lot of parallel AS2 and AS3 work. If you asked me if I wanted to do an AS2 or AS3 project, I’d probably respond AS3, unless your deadline was a week or less.
…and that’s my point. Writing AS3 is slow. It’s finally reached a maturity as a programming language; a real language, not a “scripting language” because it now officially compiles to machine code on 3 differentchip sets. As a real language, it has all the features (most, hehe… private constructor what, abstract classes who?) a traditional programmer would expect from a programming language.
My boss, a professional Java Developer who now does a lot of PHP (and I’m sure has a larger illustrious career I don’t know about yet), said that a strongly-typed language should be making me faster, not slower.
In shock and anger, I pulled my phone from my pocket, called up “Bullshit”, and requested he leap upon my bosses’ head.
There is a reason I click the “Flash” icon on my task bar, do File > New, hit F9, and test a new String parsing algorithm there in AS3 instead of going the ActionScript project route in Flex Builder… or even “new ActionScript File” and making it launching it as an Application. Flash is faster. Sure, once you get rolling, you can have some good test bed code combined with test cases even run by ANT in Flex. I’d still argue the instant gratification in Flash beats Flex.
…but it doesn’t stop there. I mean, after hearing about things such as “int promotion” and “compiler optimizations based on clear, strongly-typed variables”, AS3 can get out of control. Parsing a pipe (|) delimited string, properties separated by commas (,), with name value pairs separated by equal signs (=) has gone from 15 lines in pre AS1 to 40 in AS3 if you ensure every parsed variable is strongly typed. For an algorithm that’s only run one time very rarely, AS3 doesn’t really benefit here.
Fine? Then why not NOT strongly type so much? Only strongly-type to ensure you don’t get any type casting exceptions, and move on with life?
…because… I … can’t. It’s hard to stop. I’ve been trained by the fear of the software engineer army to strongly-type everything. To ensure the compiler has a crystal clear understanding of everything, and that my code will run at moch-10. I can have faith that the old AVM will never even need gas, because the key in the ignition for it will never be turned. All the code I write now ensures everything is typed, and all namespaces are correct.
I’ve tried abandoning namespaces and using *, Object, and even just abandoning type-casting in general for quick tests or prototypes. It’s just as time goes on, I find the code I add to those things starts getting more AS3 like.
Bottom line, it’s really really hard to break the habit. Every time I go back to AS2 for some random project, I’m reminded how damn fast it is to create things in it. Half the exceptions I get in AS3 I really don’t care about, and don’t need to know about; they don’t impact the project from working if they are small in scope. A lot of my data is either primitives or simply arrays.
For smaller projects, AS2 is still the bomb. For smaller algorithms, less strong-typing just results in less, more readable code.
…what I can’t figure out is how to drop the “good habits” that AS3 teaches you to go back to fast and furious ways of scripting languages.
13 Replies to “I have a hard time writing slow ActionScript 3”
I was just going to write about this, from a different set of circumstances. Teaching at the Art Institute, many of my students are designers and art students who don’t want or need all the strong typing and robustness of AS3 for their projects. I’m teaching them AS3, but for what they plan to do in their careers they just don’t need it. AS2 is faster and easier for them, especially for quickly building up and prototyping their designs. Unfortunately, AS3 is the new thing and the direction that the industry is moving towards, and I want them to stay current.
But, sometimes you just need a simple scripting language …
Depends the project i guess.
no typing is fun if you just want to get sometime done.
strong typing is necessary if you have to manage the f*cker
Maybe I’ve been under a rock for a long time. As I surf around for inspiration, it seems 2 years ago and further back, the level of creativity showcased online with flash was way higher than it is now. Is this because of AS3 being “slower” to write?
Turn off strict mode. It’ll be like AS2 all over again. :)
From my own personal experience scripting is always faster for prototypes and short turn around projects with 1 dev. If you know how all your scripting hacks work and the project is out the door in a week then big whoop.
However, If I had to write something that had to live for a long time and had more then 1 dev, yeah Iâ€™m going with AS3 and a known app framework.
Sometimes you just want to getUrl and swapDepth(z++) darn it.
“Turn off strict mode” ?
-No strict mode is like eating without washing your hands.
-Having it on is like looking through a microscope for the first time, and forever thinking about all those germs you’ve been eating.
Not that this is really the point of your post, but I think “Godlike” came from unreal tournament…:)
Great post, Jesse. I had been thinking the same sorts of thoughts recently. I just feel a bit more free in AS2. I know that the AS3 power is a fantastic thing, and I am moving there slowly, but sometimes I just need to get stuff done. And fast.
And I thought the godlike/killing spreee stuff came from Quake series games.
There is another option. To write code fast for specific purposes but avoid a lot of keystokes, get into writing code generators. After a certain level of mastery of OOP, the only real way to get better is to be faster, and that means automating as much as possible.
There are some good examples out there of generators, but a LOT more could be done in this regard.
To confirm Robert’s suspicion, yes, that entire soundbite is from Unreal Tournament. I played it so often that 4+ years later I still hear that voice in my head when playing online.
Great post Jesse!
I’ve posted some of my responses to my blog, and a few ideas on what could be done, just to keep the conversation going.
AS3 is great, what we need are specific methods to speed up the Design / Development process.
So, just to play the devil’s advocate here, I think you and your colleague are probably thinking differently about what fast means. For you, it sounds like it means to get some bit of code written rapidly. There is just no way that a strongly-typed language can compete here because so much is just ‘implied’ in a weakly typed language. There is another type of fast, though, that is probably more meaningful to an enterprise Java developer than a flash designer/developer. Consider a very large complex application built in AS3. As the size increases, it becomes both more difficult to maintain and find and fix bugs. To complete this application, in the sense of both coding it and getting rid of all the bugs, will actually be faster in the strongly typed language than the weakly typed language. If you are doing a little one-off project that will never grow in complexity, then a dynamic weakly typed language is definitely the way to go, but something that is longer lived and more complex, you will thank yourself if you don’t use a weakly typed language.
Comments are closed.