+ All Categories
Home > Documents > As 3 0 Standards

As 3 0 Standards

Date post: 30-May-2018
Category:
Upload: prabhu207
View: 221 times
Download: 0 times
Share this document with a friend

of 16

Transcript
  • 8/14/2019 As 3 0 Standards

    1/16

    Vendor Coding GuidelinesThis document is a description of development guidelines that are required for all codeproduction for the Pearson School Curriculum Technology Group. Actionscript 3 and ObjectOriented programming are the two major design standards which all development must follow.

    In order for code to be considered acceptable:Code must fully meet functional requirementsCode must be written in Actionscript 3.0 to attached coding standards, including fullASDoc-compatible commenting (See Actionscript 3 Style Guide).Code must compile correctly under Flash CS3.Code must include Unit test code per the attached guidelines.Code must be delivered per the schedule attached to the statement of work.Code will be reviewed by Pearson to ensure conformance to all guidelines.

    Actionscript Coding standards Page 1 The information in this document is privileged and confidential. It is intended solely for the use of authorized recipients.

  • 8/14/2019 As 3 0 Standards

    2/16

    ActionScript 3 Basic Style Guide

    FilenamesAll suffixes for ActionScript code is .as . Filenames should not contain spaces, punctuation, or any

    other special characters. Files should be named according to their content type: Classes and Interfaces use UpperCamelCase ; (example: CrosswordGame.as) Interfaces always start with an upper case I : IUpperCamelCase : (example IButton.as) Includes use lowerCamelCase ; (example: someInclude.as)

    File OrganizationAn ActionScript file must contain the following structure:1. Initial Comment2. Package definition3. Import statements (alphabetical). Use fully qualified imports, i.e., without the asterisk, unless most of a

    package is used. Otherwise, you get unnecessary file bloat.

    1. Example: import fl.display.Sprite;2. Avoid: import fl.display.*;

    4. Class or interface definition

    5. static variables (in alphabetical order, if any)6. Instance variables

    7. Constructor8. Getters and setters. Note: use sparingly ; theres no point using getter/setter in cases where a plain

    property variable would suffice). Example:

    private var isEnabled:Boolean = true;private var enabledChanged:Boolean = false;

    public function get enabled():Boolean {return isEnabled;

    }

    public function set enabled(value:Boolean):void {isEnabled = value;enabledChanged = true;

    }9. Methods (Grouped by functionality, not by scope.)

    Actionscript Coding standards Page 2 The information in this document is privileged and confidential. It is intended solely for the use of authorized recipients.

  • 8/14/2019 As 3 0 Standards

    3/16

    General rules Indent using tabs. The reference tab size is 4 spaces. Your code editor should be configured this way. Code lines should not exceed 100 characters. Separate functions/methods by one or more empty lines. Dont be afraid of using whitespace.

    DeclarationsOnly one declaration should be done per line.

    Right:

    Wrong:

    Initialize the variable, if you can.

    Right:

    var a:int = 10;var b:int = 20;var c:int = 30;

    var a:int = 10; b:int = 20; c:int = 30;

    public var isAdmin:Boolean = false;

    public var isAdmin:Boolean;//false is the default in AS3 for Boolean, not undefined!

    Wrong:

    Actionscript Coding standards Page 3 The information in this document is privileged and confidential. It is intended solely for the use of authorized recipients.

  • 8/14/2019 As 3 0 Standards

    4/16

    Curly braces and parenthesesSpaces should not be placed between the object name and type.

    Example:

    Statements

    Simple Statements Use one statement per line, even for simple statements and always end with a semicolon.

    Right:

    Wrong:

    Compound Statements Compound statements (the ones that require { and }, like switch, if, while, etc.) must have thecode inside the statement must be indented by one level. Curly braces are used in all applicablestatements, even if its only a single line.

    Return Parentheses should only be used in returns if they make the code more readable.

    public class Example extends MovieClip {

    private var ball:Object;

    public function addBall(b:Object):void {ball = b;...

    }

    public function anotherMethod():void {while (true) {

    ...}

    }}

    i++;resetBalls();

    i++; resetBalls();

    return;return getPreviewImage();return (phase ? phase : initPhase);

    Example:

    Actionscript Coding standards Page 4 The information in this document is privileged and confidential. It is intended solely for the use of authorized recipients.

  • 8/14/2019 As 3 0 Standards

    5/16

    Conditional if, else if, else

    Switch

    Loop for

    Loop for..in

    Loop for each..in

    if (condition) {simpleStatement;

    }

    if (condition) {statements;

    } else {statements;

    }

    switch ( condition ) {case ABC:

    statements ;// continue, without break

    case DEF:statements ;break;

    case JKL:case XYZ:

    statements ;return false;

    default:statements ;

    }

    for (initialization; condition; update) {statements;}

    for (var iterator:String in someObject) {statements;

    }

    for each (var iterator:String in someObject) {statements;

    }

    Actionscript Coding standards Page 5 The information in this document is privileged and confidential. It is intended solely for the use of authorized recipients.

  • 8/14/2019 As 3 0 Standards

    6/16

    Loop while

    Loop do..while

    Error handling try..catch..finally

    With finally:

    while ( condition ) {statements ;

    }

    do {statements ;

    } while ( condition );

    try {statements ;

    } catch (e: Event ) {statements ;

    }

    try {statements ;

    } catch (e: Event ) {statements ;

    } finally {statements ;

    }

    with (this) {alpha = 0.5;

    }

    With

    Spaces

    Wrapping lines Line breaks make the code cleaner by creating logical groups. Use a line break in the followingsituations:

    Between functions Between the method local variable and its first statement Before a block Before a single line comment or before a multi-line comment about a specific code

    passage Between a codes logical section to make it clearer

    Actionscript Coding standards Page 6 The information in this document is privileged and confidential. It is intended solely for the use of authorized recipients.

  • 8/14/2019 As 3 0 Standards

    7/16

    Blank spaces Use blank spaces to separate a keyword from its parentheses and dont use a space to separatethe method name from its parentheses.Example:

    A blank space must exist after every comma in an arguments list.Example:

    All binary operators must be separate from its operands by a space. Dont use a space withunary operators (++, --, etc.).Example:

    Ternary operators must be separated by blank spaces and broken in more than one line if theyare really long. Parentheses should be used to maintain readability.Example:

    Right:

    For expressions must be separated by blank spaces:

    while (true) {getSomething();

    }

    addSomething(data1, data2, data3);

    a += (5 + b) / c;while (d as int < f) {

    i++;}

    a = (expression) ? expression : expression;

    for (var i:Number; i < 5; i++) {

    Actionscript Coding standards Page 7 The information in this document is privileged and confidential. It is intended solely for the use of authorized recipients.

  • 8/14/2019 As 3 0 Standards

    8/16

    Commenting

    ASDoc Generated DocumentationComments will include ASDoc tags in them, which allows HTML documentation to be built from

    the source code, using your comments (similar to JavaDocs). As long as the comments areproperly formatted, the ASDoc tool can run and build documentation off of your source.

    Example of ASDoc HTML Documentation:

    RequirementsAll classes and functions should be commented. Variables should be commented, unless theiruse is plainly obvious. Comments need to follow the ASDoc Commenting Guidelines. Commentsshould not merely restate code into English or pseudo-code. Instead, they should describe thefunctionality of the code and how it fits into a class, module, or project.

    Right:

    Actionscript Coding standards Page 8 The information in this document is privileged and confidential. It is intended solely for the use of authorized recipients.

  • 8/14/2019 As 3 0 Standards

    9/16

    Wrong:

    ASDoc Commenting GuidelinesIn the following examples, note the extra * in the opening of the comment block. Also, note thatseveral HTML tags can be used in the comments, such as ,,.

    isrequired for paragraphs after the first. For more information, see:

    Class :

    Method:

    //bail if we have no columns to displayif (!visibleColumns || visibleColumns.length == 0) {

    return false;}

    //sets column numbers variables to zerocolNum = 0;

    /*** First sentence of a multi-paragraph description of aclass.*

    Second paragraph.

    ** @langversion ActionScript 3.0* @playerversion Flash 9** @author "Ray Koch"*/class SomeThing() {

    /*** Typical simple multiline documentation* comment. This text describes the myFunction* function.** @langversion ActionScript 3.0** @param a Describe param a here.* @param b Describe param b here.

    ** @see someOtherFunction** @example myFunction("daddy-o", 3234);*/public function myFunction(a:String, b:Number):void {}

    Actionscript Coding standards Page 9 The information in this document is privileged and confidential. It is intended solely for the use of authorized recipients.

  • 8/14/2019 As 3 0 Standards

    10/16

    Property:

    Naming Conventions for Code

    General rules Acronyms: avoid acronyms unless the abbreviation form is more usual than its full form

    (like URL, HTML, etc). Project names can be acronyms if this is the way its called; Only ASCII characters, no accents, spaces, punctuations or special characters; Dont use the name of a native Flash Player component (flash package, like IOError,

    Bitmap, etc); Never use Index to a component name since it conflicts with ASDoc tool generated docs.

    LanguageThe code itself must be in English, except for verbs and nouns that are part of the business domain (specific expertise area the software is meant to address, i.e., the real world part that isrelevant to the system).

    Right:DEFAULT_CATEGORY

    Wrong:

    PackagesThe package name must be written in lowerCamelCase, starting with small caps andother initials in upper case. The first element in a package name is the first level domain (com,org, mil, edu, net, gov). The next element is the company or client that owns the packagefollowed by as3 , then projects name and module:

    com.pearson.as3.project.moduleExamples:

    /** A private property String. */private var privateProperty:String = "Keep Off: PrivateProperty";

    addPlayer();getProductsByCategory();changeState();

    quesoCombo();mudarEstado();UsuarioObjetoDeTransferencia

    com.pearson.as3.digitalPaths.math2011.uploadModulecom.apple.quicktime.v2

    ClassesClasses names should prefer nouns, but can use adjectives as well. Always use

    Actionscript Coding standards Page 10 The information in this document is privileged and confidential. It is intended solely for the use of authorized recipients.

  • 8/14/2019 As 3 0 Standards

    11/16

    UpperCamelCase . Examples:

    InterfacesInterface names must follow the classes naming rules, with a starting uppercase I. Examples:

    Methods Methods must start with a verb and are written in lowerCamelCase. If the method iscalled on an event it should end with Handler: Examples:

    Variables Variables must use camelCase and clearly describe what they are. No prefixes or suffixes.ActionScript is strongly-typed, therefore an objects name doesnt need to and a clear andconcise name is more important than the objects type.

    Right:

    Wrong:

    Although, Boolean variables should start with can , is or has .

    Temporary variables (like the ones used in loop statements) can be a single character.The most commonly used are i, j , k, m, n, c, d.

    class LinearGradientclass DataTipRenderer

    interface ICollectionViewinterface IButt

    makeRowsAndColumns()getObjectsUnderPoint()carClickHandler()

    private var isButtonEnabled:Boolean = true;private var buttonLabels:Array = [A,B,C];public var textOnScreenNode:XMLNode = new XMLNode();

    private var data:Object = {}; //ambiguousprivate var arr_data:Array = [A,B,C]; //goofyprefixpublic var ball_mc:MovieClip = new MovieClip();//unnecessary suffixpublic var _addBall = true; //unnecessary prefix

    private var isListeningForRender:Boolean = false;private var canEditUsers:Boolean = true;private var hasAdminPrivileges:Boolean = false;

    for (var i:int = 0; i < 10; i++) {

    Actionscript Coding standards Page 11 The information in this document is privileged and confidential. It is intended solely for the use of authorized recipients.

  • 8/14/2019 As 3 0 Standards

    12/16

    Catch variables should be named e, no matter what the error type.

    Constants Constants must be all uppercase, using underscores to separate words:

    catch (e:Error) {hasFieldName = false;...

    }

    public static const DEFAULT_MEASURED_WIDTH:Number = 160;public static const AUTO:String = "auto";

    Actionscript Coding standards Page 12 The information in this document is privileged and confidential. It is intended solely for the use of authorized recipients.

  • 8/14/2019 As 3 0 Standards

    13/16

    General Practices Use the keyword FIXME inside comments to flag something thats broken and should be

    fixed. Use TODO to flag something that works but can be improved by refactoring or for

    something that needs to be done later. Assign the iterator value to a variable before using it if the performance improvement will

    be significant (e.g., in simple arrays it isnt necessary).

    Right:

    Right:

    Right:

    Wrong:

    Create/use loosely coupled components. The less a component knows about another,the greater the reuse possibilities.

    In Boolean evaluations, place the fastest ones before. If the fast one fails, the evaluationis short-circuited and we dont have to run the slow method.

    Right:

    Wrong:

    var maxPhase:Number = slowMethod();for (var i:Number = 0; i < maxPhase; i++) {

    statements;}

    var maleBabyNames:Array = ['Aaron', 'Ace', 'Alex'];var maleBabyNamesLength:Number = maleBabyNames.length;for (var i:Number = 0; i < maleBabyNamesLength ; i++) {

    trace(maleBabyNames[i]);}

    var daysOfWeek:Array = ['Mon', 'Tues', 'Wed', 'Thu','Fri'];for (var i:Number = 0; i < daysOfWeek.length(); i++) {

    trace(daysOfWeek[i]);}

    for (var i:Number = 0; i < slowMethod(); i++) {statements;

    }

    if (isAdmin && slowMethod(item)) {

    if (slowMethod(item) && isAdmin) {

    Actionscript Coding standards Page 13 The information in this document is privileged and confidential. It is intended solely for the use of authorized recipients.

  • 8/14/2019 As 3 0 Standards

    14/16

    Use constants if available.

    Right:

    Wrong:

    myButton.addEventListener(MouseEvent.CLICK, myHandler);

    myButton.addEventListener("click", myHandler);

    Use specific types if available.

    Right:

    Wrong:

    private function mouseMoveHandler(event:Event):void {

    private function mouseMoveHandler(event:MouseEvent):void{

    Anonymous functions are permissible for relatively simple situations. Example:

    myButton.addEventListener(MouseEvent.CLICK,function(event:MouseEvent):void {

    simpleStatement;}

    );

    Reserved Words Dont name things withthem.

    abstractasbooleanbreakbytecasecastcatchcharclassconstcontinuedebuggerdefaultdeletedodouble

    dynamiceachelseenumexportextendsfalsefinalfinallyfloatforfunctionget

    gotoifimplementsimportinincludeinstanceofinterfaceinternalintrinsic

    islongnamespacenativenativenewnulloverridepackageprivateprotectedprototypepublic

    returnsetshortstaticsuperswitchsynchronizedthisthrowthrows

    Actionscript Coding standards Page 14 The information in this document is privileged and confidential. It is intended solely for the use of authorized recipients.

  • 8/14/2019 As 3 0 Standards

    15/16

    totransienttruetrytypetypeofusevarvirtualvoidvolatilewhilewith

    Actionscript Coding standards Page 15 The information in this document is privileged and confidential. It is intended solely for the use of authorized recipients.

  • 8/14/2019 As 3 0 Standards

    16/16

    UNIT TESTING / ASUNIT

    Overview In order to reduce debugging time and deliver more stable software, all activities must be unit tested.ASUnit is a robust and mature framework for testing Flash Actionscript projects. The extent of testingneeded is variable. Each facet of functionality will need a test written for it.

    Following is a sample list of objectives to test for: All functions and methods that return a value Test that the proper data gets loaded Test that media loads (if activity is designed to load images, videos, etc.)

    Resources The ASUnit package includes Actionscript 2 and Actionscript 3 versions. Download the framework at:

    A good tutorial is located here:

    Asynchronous Tests Sometimes asynchronous code must be tested, such as an XML loading function. ASUnit can alsohandle this type of code. You must subclass AsynchronousTestCase instead of TestCase . You must alsosetup your listeners/callbacks so that your data is completely loaded before the run() method is called tostart the testing process. Essentially, you will be interrupting the constructor to wait for your data to loadand then continuing on to execute run() afterwards.

    Actionscript Coding standards Page 16 The information in this document is privileged and confidential. It is intended solely for the use of authorized recipients.

    http://marstonstudio.com/index.php/2007/07/28/asunit-testing-with-flash-cs3-and-actionscript-3/

Recommended