Wednesday, December 14th, 2005

Category: Flash

AS2 Coding Standards

I just wanted to blog this for reference.

Tim Scollick posted an entry about ActionScript 2 Coding Standards and raises some good questions.

One of the commentors (Derrick - nice name, bad spelling ;) ) provided a couple of links.

The first one is a Macromedia AS1 coding standards doc. I still use some of the suggestions in there, but it is made for AS1 and newbies would probably be confused because of the errors and inconsistencies in the doc.

The second link is great. I had seen this a while back but had forgotten about it. Thanks Derrick for the reminder!

And thanks to Simon Wacker for the very useful doc:
http://www.simonwacker.com/blog/archives/000087.php

There is a PDF link on the page as well for downloading.

 

One thing I don’t agree with is the method implementation mentioned as good practice:

public function getBeanName(Void):String {
    return beanName;
}

Sorry, but I really hate this implementation. To me, the code is harder to read. It seems less structured. My brain likes patterns and this breaks up visual cues that it’s a function. Same goes for loops. My preference:

public function getBeanName(Void):String
{
    return beanName;
}

Very subtle difference to some people, but it makes a big difference visually. I am not one for minimizing lines of code for the sake of doing so. Although I am guilty of using the one line if statement from time to time, but that’s laziness, not because I think it’s best practice.

At one point I was using SEPY because it folds code (awesome). However, it folds code a line below the first { character, so my preferred method implementation above made the code folding look awkward. I started using the other method implementation and liked the folding in SEPY, but the code just looked really wrong in any other editor. If you could choose how SEPY folded code that would rock!

Anyhow, Tim says he will begin a series of entries on AS2 best practices. I look forward to it.

4 Responses to 'AS2 Coding Standards'

Subscribe to comments with RSS or TrackBack to 'AS2 Coding Standards'.

  1. JesterXL | Wednesday, December 14th, 2005 | 5:41 pm

    This:

    etBeanName(Void):String

    The Void, won’t compile in Flex 1.5, Flex 2 (Flash Player 8.5 & AS3), nor MTASC.

  2. Derek Vadneau | Wednesday, December 14th, 2005 | 5:54 pm

    Yeah, I copied the code directly from Simon’s blog. Even Simon admitted that it is simply a documentation mechanism.

    I’m guessing Simon isn’t updating that page. Know of any standards docs like this that are being presented publicly? Hopefully being updated as well?

  3. Simon Wacker | Thursday, December 15th, 2005 | 5:45 am

    Hi Jester, hi derek,

    the Void will compile in Flex 1.5, but as you say not in Flex 2 and not in AS3. They are ActionScript 2 Coding Standards (as the title states). MTASC will compile it, but not in strict mode.
    Putting the curly braces on its own line is a personal design choice, I’m personally used to not doing so, others are. But all this personal choices aside, the important thing is that you and your team finds a standard everyone agrees to.
    I plan to write some more standards on classes, variables, properties and packages. I just have to find the time to write them. Knowing that someone finds these standards useful is a good motivation. Thanks.

    Cheers,
    Simon

  4. Derek Vadneau | Thursday, December 15th, 2005 | 11:45 am

    “Putting the curly braces on its own line is a personal design choice”
    Yeah, I guess my comments come off a little harsh. I was just giving my personal opinion.

    “the important thing is that you and your team finds a standard everyone agrees to”
    I couldn’t agree more. That’s why I wanted to doc the link to your page - it’s a great place to continue from.

    “I plan to write some more standards on classes, variables, properties and packages.”
    That’s awesome, Simon. I look forward to it. I need standards docs like this to keep my coding in line!

Leave a Reply

If this is your first comment it will need to be approved before it will appear.