Why ‘Convenience Methods’ Exist in ActionScript 3

LAS3W

I’ll keep this short, but the Flash Player team gets a lot of requests for “convenience methods”, functions that save you time, typing, or calculation. Unfortunately, they can’t implement every one. But, while watching Colin Moock’s Lost ActionScript 3 Weekend (which I highly recommend you buy if you’re just starting out), Jim Corbett, primary author of the DisplayList API, answers the question of why certain convenience methods get implemented and others don’t. The example Colin Moock gave him was

'displayObjectContainer.removeAllChildren()'

…asking why it wasn’t chosen. The answer is basically that it’s easy to write and only saves about 2 line of code.
“Look at the ActionScript that’s involved”, Jim answered.

‘swapChildren’ however, is a much more complicated process. When you remove one displayObject from the DisplayList, the hierarchy collapses. Then, to complicate things, whether you go pull from the top or towards the bottom of the DisplayList factors into the calculation. It quickly becomes a conditional statement monster, and that’s the type of coding that people like Jim want to help us with by creating these convenience methods. Pretty interesting, huh?

The video I mentioned is only available if you purchase the course, but, to whet your appetite, here is a 22 minute sample of the group’s talk with Jim.


23

09 2009

  • http://www.seantron.com/ Seantron

    Yep, I don’t want to have to think of which sorting algorithm I’m going to choose. But I bet you anything they just have a lame Bubble Sort. Sigh.

  • http://www.seantron.com Seantron

    Yep, I don’t want to have to think of which sorting algorithm I’m going to choose. But I bet you anything they just have a lame Bubble Sort. Sigh.

  • http://topsy.com/tb/bit.ly/1bzNX5 Tweets that mention // Commented Out » Blog Archive » Why ‘Convenience Methods’ Exist in ActionScript 3 — Topsy.com

    [...] This post was mentioned on Twitter by Adobe Software. Adobe Software said: Why ‘Convenience Methods’ Exist in ActionScript 3 http://bit.ly/1bzNX5 [...]

  • http://Visualrinse.com/ Chad

    Interesting insight… We have an AS3 API we’ve been building for a while and it always come down to questions like this… If it requires chaining more than about 3 methods or so, we consider adding a shortcut. If not, we don’t. Thanks for the post, Kevin

  • http://Visualrinse.com Chad

    Interesting insight… We have an AS3 API we’ve been building for a while and it always come down to questions like this… If it requires chaining more than about 3 methods or so, we consider adding a shortcut. If not, we don’t. Thanks for the post, Kevin

  • http://pbking.com/blog Jason Crist

    I’m actually of a different mindset. When it’s boiled down everything is a convenience method. If I can save myself and my users three lines of typing by adding something to an API (so long as the logical expectations are clearly understood) then I’ll create (or wish I had) a convenience method every time. As I go along writing code I hope that over time I can write less and less to get the same job done. It especially helps for self-documenting code. The purpose of a four line bit of logic might not be immediately obvious. But a single method that brings about the same execution is much easier to immediately understand.

  • http://pbking.com/blog Jason Crist

    I’m actually of a different mindset. When it’s boiled down everything is a convenience method. If I can save myself and my users three lines of typing by adding something to an API (so long as the logical expectations are clearly understood) then I’ll create (or wish I had) a convenience method every time. As I go along writing code I hope that over time I can write less and less to get the same job done. It especially helps for self-documenting code. The purpose of a four line bit of logic might not be immediately obvious. But a single method that brings about the same execution is much easier to immediately understand.

  • http://devnotes.posterous.com/ George Girton

    ok, Seantron, you’re on. Dinner at Puro Sabor, the inexpensive but amazing Peruvian restaurant in Van Nuys, California, next time you’re in Los Angeles. It can’t possibly be a bubble sort. Loser buys dinner, winner brings a six pack.

  • http://devnotes.posterous.com George Girton

    ok, Seantron, you’re on. Dinner at Puro Sabor, the inexpensive but amazing Peruvian restaurant in Van Nuys, California, next time you’re in Los Angeles. It can’t possibly be a bubble sort. Loser buys dinner, winner brings a six pack.

blog comments powered by Disqus