• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
It세미나 Naming Guidlines For Flex
 

It세미나 Naming Guidlines For Flex

on

  • 794 views

 

Statistics

Views

Total Views
794
Views on SlideShare
794
Embed Views
0

Actions

Likes
0
Downloads
0
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Microsoft Word

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    It세미나 Naming Guidlines For Flex It세미나 Naming Guidlines For Flex Document Transcript

    • IT사업팀 개발 표준<br />Flex SDK coding conventions and best practices<br />Adobe Open Source.<br />Last Modified: 2008-02-24 19:33:43.0 Powered by Atlassian Confluence 2.7.1, the Enterprise Wiki.<br />Flex SDK coding conventions and best practices<br />Note: This page is not yet complete and has some sections marked TBD. But there's plenty here to get you started!<br />Introduction<br />This document lays out the coding standards for writing open-source Flex framework components in ActionScript 3. Adhering to these standards makes the source code look consistent, well-organized, and professional.<br />Some of these standards are completely arbitrary, since there is not always a “best way” to code. Nevertheless, in the interest of consistency, all commits to the Flex SDK project will be expected to follow these conventions.<br />Contents<br />NamingLanguage UsageFile OrganizationFormattingASDoc<br />Naming<br />Choosing good names is critical to creating code that is easy to use and easy to understand. You should always take the time to think about whether you have chosen the right name for something, especially if it is part of the public API.<br />Our naming standards are mostly consistent with those of ECMAScript and Flash Player 9.<br />Abbreviations<br />Avoid them as a general rule. For example, calculateOptimalValue() is a better method name than calcOptVal().<br />Being clear is more important than minimizing keystrokes. And if you don't abbreviate, developers won't have to remember whether you shortened a word like “qualified” to “qual” or “qlfd”.<br />However, we have standardized on a few abbreviations:<br />acc for accessibility, as in ButtonAccImpl <br />auto for automatic, as in autoLayout <br />auto for automatic, as in autoLayout <br />eval for evaluate, as in EvalBindingResponder <br />impl for implementation, as in ButtonAccImpl <br />info for information, as in GridRowInfo <br />num for number of, as in numChildren <br />min for minimum, as in minWidth <br />max for maximum, as in maxHeight <br />nav for navigation, as in NavBar <br />regexp for regular expression, as in RegExpValidator <br />util for utility, as in StringUtil <br />This list probably does not include all abbreviations that are currently in use. If you're considering using an abbreviation that isn't listed here, please search the source code to determine whether it is already in use. If you don't find it, think twice about whether abbreviating is really appropriate.<br />Occasionally we are (deliberately) inconsistent about abbreviations. For example, we spell out “horizontal” and “vertical” in most places, such as horizontalScrollPolicy and verticalScrollPolicy but we abbreviate them to H and V in the very-commonly-used container names HBox and VBox.<br />Acronyms<br />Various acronyms are common in Flex, such as AIR, CSS, HLOC, IME, MX, MXML, RPC, RSL, SWF, UI, UID, URL, WSDL, and XML.<br />An acronym is always all-uppercase or all-lowercase (e.g., SWF or swf, but never Swf). The only time that all-lowercase is used is when the acronym is used by itself as an identifier, or at the beginning of an identifier, and the identifier should start with a lowercase letter. See the rules below for which identifiers should start with which case.<br />Examples of identifiers with acronyms are CSSStyleDeclaration, IUID, uid, IIME, and imeMode.<br />Word boundaries<br />When an identifier contains multiple words, we use two ways of indicating word boundaries: intercaps (as in LayoutManager or measuredWidth) and underscores (as in object_proxy). See the rules below for which method to use.<br />Sometimes it isn't clear whether a word combination has become its own single word, and we are unforunately inconsistent about this in some places: dropdown, popUp, pulldown.<br />Follow the acronym-casing rules even in the rare case that two acronyms must be adjacent. An example (which isn't actually in use) would be something like loadCSSURL(). But try to avoid such names.<br />Type-specifying names<br />If you want to incorporate the type into the name, make it the last “word”. Don't use the old ActionScript 1 convention of concatenating abbreviated type suffixes such as _mc to indicate type. For example, name a border Shape border, borderSkin, or borderShape, but not border_mc.<br />Often, the best name for an object is simply the same as its type, with different casing:<br />var button:Button = new Button();<br />Package names<br />Start them with a lowercase letter and use intercaps for subsequent words: controls, listClasses.<br />Package names should always be nouns or gerunds (the -ing noun form of a verb), not verbs, adjectives, or adverbs.<br />A package implementing lots of similar things should have a name which is the plural form of the thing: charts, collections, containers, controls, effects, events, formatters, managers, preloaders, resources, skins, states, styles, utils, validators.<br />It is common to use a gerund for the name of a package which implements a concept: binding, logging, messaging, printing. Otherwise, they are generally " concept nouns" : accessibility, core, graphics, rpc.<br />A package containing classes that support component FooBar should be called fooBarClasses.<br />File names<br />For importable APIs, the file name must be the same as the public API inside. But include files don't have to follow this rule.<br />Start the names of include files for [Style(...)] metadata with an uppercase letter, use intercaps for subsequent words, and make the last word “Styles”: BorderStyles.as, ModalTransparencyStyles.as.<br />Start the names of individual asset files with a lowercase letter and use underscores between words: icon_align_left.png.<br />Namespace names<br />Start them with a lowercase letter and use underscores between words: mx_internal, object_proxy.<br />Interface names<br />Start them with I and use intercaps for subsequent words: IList, IFocusManager, IUID.<br />Class names<br />Start them with an uppercase letter and use intercaps for subsequent words: Button, FocusManager, UIComponent.<br />Name Event subclasses FooBarEvent.<br />Name Error subclasses FooBarError.<br />Name the EffectInstance subclass associated with effect FooBar FooBarInstance.<br />Name Formatter subclasses FooBarFormatter.<br />Name Validator subclasses FooBarValidator.<br />Name skinning classes FooBarBackground, FooBarBorder, FooBarSkin, FooBarIcon, FooBarIndicator, FooBarSeparator, FooBarCursor, etc.<br />Name utility classes FooBarUtil (not FooBarUtils; the package is plural but the class is singular).<br />It is common to name a base class FooBarBase: ComboBase, DateBase, DataGridBase, ListBase.<br />Event names<br />Start them with a lowercase letter and use intercaps for subsequent words: " move" , " creationComplete" .<br />Style names<br />Start them with a lowercase letter and use intercaps for subsequent words: color, fontSize.<br />Enumerated values for String properties<br />Start them with a lowercase letter and use intercaps for subsequent words: " auto" , " filesOnly" , <br />Constant names<br />Use all uppercase letters with underscores between words: OFF, DEFAULT_WIDTH.<br />The words in the identifier must match the words in the constant value if it is a String:<br />public static const FOO_BAR:String = " fooBar" ;<br />Property (variable and getter/setter) names<br />Start them with a lowercase letter and use intercaps for subsequent words: i, width, numChildren.<br />Use i for a loop index and n for its upper limit. Use j for an inner loop index and m for its upper limit.<br />for (var i:int = 0; i < n; i++)<br />{<br /> for (var j:int = 0; j < m; j++)<br /> {<br /> ...<br /> }<br />}<br />Use p (for “property”) for a for-in loop variable:<br />for (var p:String in o)<br />{<br /> ...<br />}<br />If a class overrides a getter/setter and wants to continue to expose the base getter/setter, it should do so by implementing a property whose name is the base name with a $ prepended. This getter/setter should be marked final and should do nothing more than call the supergetter/setter.<br />mx_internal final function get $numChildren():int<br />{<br /> return super.numChildren;<br />}<br />Storage variable names<br />Give the storage variable for the getter/setter foo the name _foo.<br />Method names<br />Start them with a lowercase letter and use intercaps for subsequent words: measure(), updateDisplayList().<br />Method names should always be verbs.<br />Parameterless methods should generally not be named getFooBar() or setFooBar(); these should be implemented as getter/setters instead. However, if getFooBar() is a slow method requiring a large amount of computation, it should be named findFooBar(), calculateFooBar(), determineFooBar(), etc. to suggest this, rather than being a getter.<br />If a class overrides a method and wants to continue to expose the base method, it should do so by implementing a method whose name is the base name with a $ prepended. This method should be marked final and should do nothing more than call the supermethod.<br />mx_internal final function $addChild(child:DisplayObject):DisplayObject<br />{<br /> return super.addChild(child);<br />}<br />Event handler names<br />Event handlers should be named by concatenating “Handler” to the type of the event: mouseDownHandler().<br />If the handler is for events dispatched by a subcomponent (i.e., not this), prefix the handler name with the subcomponent name and an underscore: textInput_focusInHandler().<br />Argument names<br />Use value for the argument of every setter:<br />Do this:<br />public function set label(value:String):void<br />Not this:<br />public function set label(lab:String):void<br />Or this:<br />public function set label(labelValue:String):void<br />Or this:<br />public function set label(val:String):void<br />Use event (not e, evt, or eventObj) for the argument of every event handler:<br />protected function mouseDownHandler(event:Event):void<br />Resource bundle names<br />If a resource bundle contains resources for a particular package, name the bundle the same as the package: controls, {formatters}}, validators. <br />Resource key names<br />Start them with a lowercase letter and use intercaps for subsequent words: pm, dayNamesShort.<br />Miscellaneous nomenclature<br />Avoid “object” because it is vague.<br />An “item” is a data item, not a DisplayObject.<br />A “renderer” is a DisplayObject that displays a data item.<br />A “type” is an AS3 type; use " kind" otherwise.<br />Language Usage<br />This section discusses how we use the language constructs of ActionScript 3, especially when there are multiple ways to express the same thing.<br />Compilation options<br />Compile with the options -strict and -show-actionscript-warnings. (These are the defaults in the flex-config.xml file.)<br />Property-based APIs<br />Favor property-based APIs rather than method-based APIs, because these are more suitable for declarative-style MXML programming.<br />Type declarations<br />Write a type annotation for every constant, variable, function argument, and function return value, even if the annotation is simply :* to indicate “no type”.<br />Do this:<br />var value:*;<br />Not this:<br />var value;<br />Use the narrowest type that is appropriate. For example, a loop index should be a int, not a Number, and certainly not an Object or *. As another example, a mouseDownHandler should declare its argument as event:MouseEvent, not event:Event.<br />Use int for integers, even if they can't be negative. Use uint only for RGB colors, bit masks, and other non-numeric values.<br />Use * only if the value can be undefined. You should generally use Object rather than *, with null being the “object doesn't exist” value.<br />If you declare something to be of type Array, add a comment of the form /* of ElementType */ immediately after Array indicate the type of the array elements. A future version of the language is likely to have typed arrays.<br />Do this:<br />var a:Array /* of String */ = [];<br />Not this:<br />var a:Array = [];<br />And this:<br />function f(a:Array /* of Number */):Array /* of Object */<br />{<br /> ...<br />}<br />Not this:<br />function f(a:Array):Array<br />Literals<br />undefined<br />Avoid using this when possible. It is only necessary when dealing with values whose compile-time is type is *, and you should be using * sparingly as well.<br />int and uint literals<br />Do not use a decimal point in a integer.<br />Do this:<br />2<br />Not this:<br />2.<br />Use a lowercase x and uppercase A-Z in hexadecimal numbers.<br />Do this:<br />0xFEDCBA<br />Not this:<br />0Xfedcba <br />Always write an RGB color as a six-digit hexadecimal number.<br />Do this:<br />private const BLACK:uint = 0x000000;<br />Not this:<br />private const BLACK:uint = 0; <br />When dealing with indices, use the value -1 to mean “no index”.<br />Number literals<br />If a Number value typically can be fractional, indicate this by using a decimal point, and follow the decimal point by a single trailing zero.<br />Do this:<br />alphaFrom = 0.0;<br />alphaTo = 1.0;<br />Not this:<br />alphaFrom = 0;<br />alphaTo = 1;<br />However, don't do this for pixel coordinates, which are by convention integral even though they can in principle be fractional.<br />Do this:<br />var xOffset:Number = 3;<br />Not this:<br />var xOffset:Number = 3.0;<br />Use e, not E, when using exponential notation.<br />Do this:<br />1.0e12<br />Not this:<br />1.0E12<br />Use the default value NaN as the “not set” value for a Number.<br />String literals<br />Use quotation marks (double quotes), not apostrophes (single quotes), to delimit strings, even if that string contains a quotation mark as a character.<br />Do this:<br />" What's up, quot; Big Boyquot; ?" <br />Not this:<br />'What's up, " Big Boy" ?'<br />Use u, not U, for unicode escape sequences.<br />Array literals<br />Use Array literals rather than new Array().<br />Do this:<br />[]<br />Not this:<br />new Array()<br />And this:<br />[ 1, 2, 3 ]<br />Not this:<br />new Array(1, 2, 3)<br />Use the Array constructor only to allocate an array of a prespecified size, as in new Array(3), which means [ undefined, undefined, undefined ], not [ 3 ].<br />Object literals<br />Use Object literals rather than new Object().<br />Do this:<br />{}<br />Not this:<br />new Object()<br />And this:<br />o = { a: 1, b: 2, c: 3 };<br />Not this:<br />o = new Object();<br />o.a = 1; <br />o.b = 2; <br />o.c = 3;<br />Or this:<br />o = {};<br />o.a = 1; <br />o.b = 2; <br />o.c = 3;<br />Function literals<br />Avoid using function literals to define anonymous functions; use a class method or package function instead.<br />If you must use a function literal, declare a return type, and terminate the last statement inside the function block with a semicolon.<br />Do this:<br />function(i:int):void { doIt(i - 1); doIt(i + 1); }<br />Not this:<br />function(i:int) { doIt(i - 1); doIt(i + 1) }<br />RegExp literals<br />Use the literal notation rather than constructing a RegExp instance from a String.<br />Do this:<br />var pattern:RegExp = /d+/g;<br />Not this:<br />var pattern:RegExp = new RegExp(" +" , " g" );<br />XML and XMLList literals<br />Use the literal notation rather than constructing an XML instance from a String.<br />Do this:<br />var node:XML = <name first=" Jane" last=" Doe" />;<br />Not this:<br />var node:XML = new XML(" <name first=quot; Janequot; last=quot; Doequot; />" );<br />Use double-quotes rather than single-quotes around XML attribute values:<br />Do this:<br />var node:XML = <name first=" Jane" last=" Doe" />;<br />Not this:<br />var node:XML = <name first='Jane' last='Doe'/>;<br />Class literals<br />Use a fully-qualified class literal only if necessary to disambiguate between two imported classes with the same unqualified name.<br />Do this:<br />import mx.controls.Button;<br />...<br />var b:Button = new Button();<br />Not this:<br />import mx.controls.Button;<br />...<br />var b:Button = new mx.controls.Button();<br />But here a fully-qualified name is required and therefore qppropriate:<br />import mx.controls.Button;<br />import my.controls.Button;<br />...<br />var b:Button = new mx.controls.Button();<br />Expressions<br />Parentheses<br />Don't use unnecessary parentheses with common operators such as +, -, *, /, &&, ||, <, <=, >, >=, ==, and !=.<br />Do this:<br />var e:Number = a * b / (c + d);<br />Not this:<br />var e:Number = (a * b) / (c + d);<br />And this:<br />var e:Boolean = a && b || c == d;<br />Not this:<br />var e:Boolean = ((a && b) || (c == d));<br />The precedence rules for other operators are harder to remember, so parentheses can be helpful with them.<br />Coercion<br />Don't compare a Boolean value to true or false; it already is one or the other.<br />Do this:<br />if (flag)<br />Not this:<br />if (flag == true)<br />Do this:<br />var flag:Boolean = a && b;<br />Not this:<br />var flag:Boolean = (a && b) != false;<br />Explicitly coerce an int, uint, Number or String to a Boolean:<br />Do this:<br />if (n != 0)<br />Not this:<br />if (n)<br />And this:<br />if (s != null && s != " " )<br />Not this:<br />if (s)<br />Let object references implicitly coerce to a Boolean:<br />Do this:<br />if (child)<br />Not this:<br />if (child != null)<br />And this:<br />if (!child)<br />Not this:<br />if (child == null)<br />Prefer the use of a cast to the use of the as operator. Use the as operator only if the coercion might fail and you want the expression to evaluate to null instead of throwing an exception.<br />Do this:<br />IUIComponent(child).document<br />Not this:<br />(child as IUIComponent).document<br />Comparison<br />Write comparisons in the order that they read most naturally:<br />Do this:<br />if (n == 3) // " if n is 3" <br />Not this:<br />if (3 == n) // " if 3 is n" <br />++ and -- operators<br />In cases where the postfix and prefix forms are equivalent, use the postfix form. Use the prefix form only when you need to use the value before it is incremented.<br />Do this:<br />for (var i:int = 0; i < n; i++)<br />Not this:<br />for (var i:int = 0; i < n; ++i)<br />Ternary operator<br />Use a ternary operator in place of a simple if/else statement, especially for null checks:<br />Do this:<br />return item ? item.label : null;<br />Not this:<br />if (!item)<br /> return null;<br />return item.label;<br />But don't use nested ternary operators in place of complex if/else logic.<br />Do this:<br />if (a < b)<br /> return -1;<br />else if (a > b)<br /> return 1;<br />return 0;<br />Not this:<br />return a < b ? -1 : (a > b ? 1 : 0);<br />new operator<br />Use parentheses after the class reference, even if the constructor takes no arguments.<br />Do this:<br />var b:Button = new Button();<br />Not this:<br />var b:Button = new Button;<br />Statements<br />Terminate each statement with a semicolon. Do not use the optional-semicolon feature of ActionScript 3.<br />Do this:<br />a = 1;<br />b = 2;<br />c = 3;<br />Not this:<br />a = 1<br />b = 2<br />c = 3<br />include statements<br />Use include, not the deprecated #include. Terminate the include statement with a semicolon, like any other statement.<br />Do this:<br />include " ../core/ComponentVersion.as" ;<br />Not this:<br />#include " ../core/ComponentVersion.as" <br />Use relative, not absolute, paths.<br />import statements<br />Import specific classes, interfaces, and package-level functions rather than using the * wildcard.<br />Do this:<br />import mx.controls.Button;<br />import flash.utils.getTimer;<br />Not this:<br />import mx.core.*;<br />use namespace statements<br />Avoid them; use :: syntax instead on each reference to something in a non-open namespace.<br />Do this:<br />import mx.core.mx_internal;<br />// Later, in some method...<br />mx_internal::doSomething();<br />Not this:<br />import mx.core.mx_internal;<br />use namespace mx_internal;<br />// Later, in some method...<br />doSomething();<br />if statements<br />If the various branches of an if/else statement involve single statements, don't make them into blocks.<br />Do this:<br />if (flag)<br /> doThing1();<br />Not this:<br />if (flag)<br />{<br /> doThing1();<br />}<br />And this:<br />if (flag)<br /> doThing1();<br />else<br /> doThing2():<br />Not this:<br />if (flag)<br />{<br /> doThing1();<br />}<br />else<br />{<br /> doThing2();<br />}<br />But if any branch has multiple statements, make all of them into blocks.<br />Do this:'<br />if (flag)<br />{<br /> doThing1();<br />}<br />else<br />{<br /> doThing2();<br /> doThing3();<br />}<br />Not this:<br />if (flag)<br /> doThing1();<br />else<br />{<br /> doThing2();<br /> doThing3();<br />}<br />When doing multiple error checks, use sequential if statements that test for failure and return early. The successful execution flow is then down the page, with the succesful return at the end of the method. Do not use nested tests for success, which make the execution flow drift across the page.<br />Do this:<br />if (!condition1)<br /> return false;<br />...<br />if (!condition2)<br /> return false;<br />...<br />if (!condition2)<br /> return false;<br />...<br />return true;<br />Not this:<br />if (condition1)<br />{<br /> ...<br /> if (condition2)<br /> {<br /> ...<br /> if (condition3)<br /> {<br /> ...<br /> return true;<br /> }<br /> }<br />}<br />return false;<br />for statements<br />Make the body of a for loop be a block, even if it consists of only one statement.<br />Do this:<br />for (var i:int = 0; i < 3; i++)<br />{<br /> doSomething(i);<br />}<br />Not this:<br />for (var i:int = 0; i < 3; i++)<br /> doSomething(i);<br />Store the upper limit for a for-loop variable in a local variable so that it isn't re-evaluated every time through the loop (unless, of course, it needs to be re-evaluated on each interation).<br />Do this:<br />var n:int = a.length;<br />for (var i:int = 0; i < n; i++)<br />{<br /> ...<br />}<br />Not this:<br />for (var i:int = 0; i < a.length; i++)<br />{<br /> ...<br />}<br />Declare the loop var inside the parentheses of the for statement, unless it is reused elsewhere.<br />Do this:<br />for (var i:int = 0; i < 3; i++)<br />Not this:<br />var i:int;<br />for (i = 0; i < 3; i++)<br />{<br /> ...<br />}<br />while statements<br />Make the body of a while loop be a block, even if it consists of only one statement.<br />Do this:<br />while (i < n)<br />{<br /> doSomething(i);<br />}<br />Not this:<br />while (i < n)<br /> doSomething(i);<br />do statements<br />Make the body of a do loop be a block, even if it consists of only one statement.<br />Do this:<br />do<br />{<br /> doSomething(i);<br />}<br />while (i < n);<br />Not this:<br />do<br /> doSomething(i);<br />while (i < n);<br />switch statements<br />Make the body of each case clause, and of the default clause, be a block. Put the break or return statement within the block, not after it. If you are returning, don't put a break after the return. Treat the default clause similarly to the case clauses; break or return from it rather than falling through the bottom of the switch.<br />Do this:<br />switch (n)<br />{<br /> case 0:<br /> {<br /> foo();<br /> break;<br /> }<br /> case 1:<br /> {<br /> bar();<br /> return;<br /> }<br /> case 2:<br /> {<br /> baz();<br /> return;<br /> }<br /> default:<br /> {<br /> blech();<br /> break;<br /> }<br />}<br />Not this:<br />switch (n)<br />{<br /> case 0:<br /> foo();<br /> break;<br /> case 1:<br /> {<br /> bar();<br /> }<br /> break;<br /> case 2:<br /> baz();<br /> return;<br /> break;<br /> default:<br /> blech();<br />}<br />return statements<br />Do not enclose a return value in unnecessary parentheses.<br />Do this:<br />return n + 1;<br />Not this:<br />return (n + 1);<br />Returning from the middle of a method is OK.<br />Declarations<br />Don't declare multiple constants or variables in a single declaration.<br />Do this:<br />var a:int = 1;<br />var b:int = 2;<br />Not this:<br />var a:int = 1, b:int = 2;<br />The override keyword<br />If present, put this first, before the access specifier.<br />Do this:<br />override protected method measure():void<br />Not this:<br />protected override method measure():void<br />Access specifiers<br />Put an explicit access specifier everywhere that one is allowed. Do not use the fact that internal is the implicit access specifier if none is written.<br />Before making an API public or protected, think hard about whether it is really needs to be. Public and protected APIs must be documented. They must also be supported for several releases before being formally deprecated.<br />The static keyword<br />If present, put this after the access specifier.<br />Do this:<br />public static const MOVE:String = &quot;move&quot;<br />Not this:<br />static public const MOVE:String = &quot;move&quot;;<br />The final keyword<br />If present, put this after the access specifier.<br />Do this:<br />public final class BoxDirection<br />Not this:<br />final public class BoxDirection<br />Declare all “enum classes” to be final.<br />Also declare “base” properties and methods (those starting with $) to be final.<br />Constants<br />All constants should be static. There is no reason to use an instance constant, since all instances would store the same value.<br />Do this:<br />public static const ALL:String = " all" ;<br />Not this:<br />public const ALL:String = " all" ;<br />Variables<br />If a variable needs to be initialized to a non-default value, do this in the declaration, not in the constructor.<br />Do this:<br />private var counter:int = 1;<br />Not this:<br />private var counter:int;<br />...<br />public function MyClass()<br />{<br /> super();<br /> ...<br /> counter = 1;<br />}<br />Local variables<br />Declare local variables at or just before the point of first use. Don't declare them all at the top of the function.<br />Do this:<br />private function f(i:int, j:int):int<br />{<br /> var a:int = g(i - 1) + g(i + 1);<br /> var b:int = g(a - 1) + g(a + 1);<br /> var c:int = g(b - 1) + g(b + 1);<br /> return (a * b * c) / (a + b + c);<br />}<br />Not this:<br />private function f(i:int, j:int):int<br />{<br /> var a:int;<br /> var b:int;<br /> var c:int;<br /> a = g(i - 1) + g(i + 1);<br /> b = g(a - 1) + g(a + 1);<br /> c = g(b - 1) + g(b + 1);<br /> return (a * b * c) / (a + b + c);<br />}<br />Declare local variables only one per function. ActionScript 3 doesn't have block-scoped locals.<br />Do this:<br />var a:int;<br />if (flag)<br />{<br /> a = 1;<br /> ...<br />}<br />else<br />{<br /> a = 2;<br /> ...<br />}<br />Not this:<br />if (flag)<br />{<br /> var a:int = 1;<br /> ...<br />}<br />else<br />{<br /> var a:int = 2;<br /> ...<br />}<br />And this:<br />var i:int;<br />for (i = 0; i &lt; n; i++)<br />{<br /> ...<br />}<br />for (i = 0; i &lt; n; i++)<br />{<br /> ...<br />}<br />Not this:<br />for (var i:int = 0; i &lt; n; i++)<br />{<br /> ...<br />}<br />for (var i:int = 0; i &lt; n; i++)<br />{<br /> ...<br />}<br />Classes<br />If a class simply extends Object, omit the extends Object clause.<br />The only “bare statements” in a class should be calls to static class initialization methods, such as loadResources().<br />Constructors<br />If a classes has instance members, write a constructor, and make it explicitly call super(), even if it does nothing else.<br />If the constructor takes arguments that set instance vars, give the the same names as the instance vars.<br />Do this:<br />public function MyClass(foo:int, bar:int)<br />{<br /> this.foo = foo;<br /> this.bar = bar;<br />}<br />Not this:<br />public function MyClass(fooVal:int, barVal:int)<br />{<br /> foo = fooVal;<br /> bar = barVal;<br />}<br />Don't set the classes' instance vars in the constructor; do this in the declarations of the instance vars. However, if you need to reset the values of inherited instance vars, do this in the consturctor.<br />Interfaces<br />TBD<br />Namespaces<br />TBD<br />Implementing properties<br />TBD<br />Metadata<br />TBD<br />Packages<br />One public API (usually a class, sometimes a namespace or function) inside the package statement.<br />Helper classes<br />bare statements<br />File Organization<br />This section presents the order in which a Flex framework file should be organized.<br />Copyright notice<br />Include a copyright notice at the top of every .as file in the framework. The format for the 2008 open-source copyright is given below.<br />////////////////////////////////////////////////////////////////////////////////<br />//<br />// ADOBE SYSTEMS INCORPORATED<br />// Copyright 2008 Adobe Systems Incorporated<br />// All Rights Reserved.<br />//<br />// NOTICE: Adobe permits you to use, modify, and distribute this file<br />// in accordance with the terms of the license agreement accompanying it.<br />//<br />////////////////////////////////////////////////////////////////////////////////<br />Note that it is 80 characters wide.<br />package statement<br />TBD<br />import statements<br />TBD<br />use namespace statement<br />TBD<br />Class metadata<br />Organize the class metadata into sections, in the order Events, Styles, Effects, Excluded APIs, and Other Metadata.<br />Put a minor section header before each section. Note that the minor section headers are 40 characters wide and that there are two spaces between the // and the section name. <br />Alphabetize the metadata by name=" ..." within each section. In the Other Metadata section, alphabetize them by metadata tag name.<br />//--------------------------------------<br />// Events<br />//--------------------------------------<br />/<br />**<br /> * ASDoc comment.<br /> */<br />[Event<br />/**<br /> * ASDoc comment.<br /> */<br />[Event<br />//--------------------------------------<br />// Styles<br />//--------------------------------------<br />/**<br /> * ASDoc comment.<br /> */<br />[Style<br />/**<br /> * ASDoc comment.<br /> */<br />[Style]<br />//--------------------------------------<br />// Effects<br />//--------------------------------------<br />/**<br /> * ASDoc comment.<br /> */<br />[Effect<br />/**<br /> * ASDoc comment.<br /> */<br />[Effect]<br />//--------------------------------------<br />// Excluded APIs<br />//--------------------------------------<br />[Exclude(name=&quot;horizontalAlign&quot;, kind=&quot;style&quot;)]<br />[Exclude(name=&quot;verticalAlign&quot;, kind=&quot;style&quot;)]<br />//--------------------------------------<br />// Other metadata<br />//--------------------------------------<br />[DefaultBindingProperty(source=&quot;text&quot;, destination=&quot;text&quot;)]<br />[IconFile(&quot;Text.png&quot;)]<br />Class declaration<br />TBD<br />include statement for Version.as<br />Every class should include core/Version.as using a relative path. This file contains the declaration for static const VERSION:String.<br />include " ../core/Version.as" ;<br />Implementation notes<br />TBD<br />Class initialization<br />TBD<br />Class constants<br />Put static const declarations here.<br />ActionScript 3 does not allow a constant to have type Array or Object. Declare such constants using static var rather than static const, but put them in this section because they are conceptually constants.<br />Class mix-ins<br />Declare any static variables of type Function that get mixed in rather than being declared as methods.<br />Class resources<br />TBD<br />Class variables<br />TBD<br />Class properties<br />Declare static getters and setters here. Order them alphabetically by property name. Use a minor separator with the property name for each one. Put the getter before the setter.<br />Class methods<br />Put static function declarations here.<br />Constructor<br />TBD<br />Variables<br />TBD<br />Overridden properties<br />Put overrides of non-static getters and setters here. Order them alphabetically by property name. Use a minor separator with the property name for each one. Put the getter before the setter.<br />Properties<br />Put new non-static getters and setters here. Order them alphabetically by property name. Use a minor separator with the property name for each one. Put the getter before the setter.<br />Overridden methods<br />Put overrides of non-static functions here.<br />Methods<br />Put new non-static functions here.<br />Overridden event handlers<br />Put overrides of event handlers here.<br />Event handlers<br />Put new event handlers here.<br />Out-of-package helper classes<br />TBD<br />Formatting<br />This section covers how a Flex framework class should be formatted.<br />Line width<br />Wrap code to 80-character lines. This has the following advantages:<br />Developers with smaller screens don't have to scroll horizontally to read long lines. <br />A comparison utility can display two versions of a file side-by-side. <br />The font size can be increased for projection before a group without requiring scrolling. <br />The source code can be printed without clipping or wrapping. <br />Indentation<br />Use 4-space indentation. Configure your text editor to insert spaces rather than tabs. This allows another program that uses a different indentation setting, such as Notepad with its 8-character indents, to display the code without disfiguring it.<br />Section separators<br />The major section separators inside a class look like this:<br /> //--------------------------------------------------------------------------<br /> //<br /> // Overridden methods<br /> //<br /> //--------------------------------------------------------------------------<br />They extend from column 4 through column 80. The text is indented to column 8.<br />The minor section separators inside a class, such as between properties, look like this:<br /> //----------------------------------<br /> // visible<br /> //----------------------------------<br />They extend from column 4 through column 40. The text is indented to column 8.<br />Put a single blank line above and below the separators.<br />Separation of declarations<br />Use a single blank line as a vertical separator between constant, variable, or function declarations.<br />/**<br /> * @private<br /> * Holds something.<br /> */<br />var a:Number;<br />/**<br /> * @private<br /> */<br />var b:Number<br />Metadata<br />TBD<br />Do this:<br />Inspectable[a=" 1" , b=" 2" ]<br />Not this:<br />Inspectable[a=1 b=2]<br />Array indexing<br />Don't put any spaces before or after the left bracket or before the right bracket.<br />Do this:<br />a[0]<br />Not this:<br />a[ 0 ]<br />Commas<br />Follow a comma with a single space. This applies to argument lists, array literals, and object literals.<br />Array literals<br />Put a single space after the left bracket and a single space before the right bracket, and put a single space after (but none before) each comma.<br />Do this:<br />[ 1, 2, 3 ]<br />Not these:<br />[1, 2, 3]<br /> <br />[1,2,3]<br />An empty array is a special case.<br />Do this:<br />[]<br />Not this:<br />[ ]<br />Format lengthy array initializers requiring multiple lines with aligned brackets:<br />static var numberNames:Array /* of String */ =<br />[<br /> " zero" ,<br /> " one" ,<br /> " two" ,<br /> " three" ,<br /> " four" ,<br /> " five" ,<br /> " six" ,<br /> " seven" ,<br /> " eight" ,<br /> " nine" <br />];<br />Object literals<br />Put a single space after the left brace and a single space before the right brace, and put a single space after the colon separating the property name and value.<br />Do this:<br />{ a: 1, b: 2, c: 3 }<br />Not these:<br />{a: 1, b: 2, c: 3}<br />{a:1, b:2, c:3}<br />{a:1,b:2,c:3}<br />An empty Object is a special case.<br />Do this:<br />{}<br />Not this:<br />{ }<br />Format lengthy object initializers requiring multiple lines with aligned braces:<br />private static var TextStyleMap:Object =<br />{<br /> color: true,<br /> fontFamily: true,<br /> fontSize: true,<br /> fontStyle: true,<br /> fontWeight: true,<br /> leading: true,<br /> marginLeft: true,<br /> marginRight: true,<br /> textAlign: true,<br /> textDecoration: true,<br /> textIndent: true<br />};<br />Function literals<br />TBD<br />var f:Function;<br />f = function():void<br />{<br /> doSomething();<br />};<br />Type declarations<br />Don't put any spaces before or after the colon that separates a variable, parameter, or function from its type.<br />Do this:<br />var n:Number;<br />Not these:<br />var n : Number;<br />var n: Number;<br />And this:<br />function f(n:Number):void<br />Not these:<br />function f(n : Number) : void<br />function f(n: Number): void<br />Operators and assignments<br />Put a single space around the assignment operator.<br />Do this:<br />a = 1;<br />Not this:<br />a=1;<br />Put a single space around infix operators.<br />Do this:<br />a + b * c<br />Not this:<br />a+b*c<br />Put a single space around comparison operators.<br />Do this:<br />a == b<br />Not this:<br />a==b<br />Don't put any spaces between a prefix operator and its operand.<br />Do this:<br />!o<br />Not this:<br />! o<br />Don't put any spaces between a postfix operator and its operand.<br />Do this:<br />i++<br />Not this:<br />i ++<br />Statements<br />Start each statement on a new line, so that you can set a breakpoint on any statement.<br />Do this:<br />a = 1;<br />b = 2;<br />c = 3;<br />Not this:<br />a = 1; b = 2; c = 3;<br />Align the braces of statement blocks.<br />Do this:<br />function f():void<br />{<br /> var n:int = numChildren;<br /> for (var i:int = 0; i < n; i++)<br /> {<br /> if ()<br /> {<br /> x = horizontalGap * i;<br /> y = verticalGap * i;<br /> }<br /> }<br />}<br />Not this:<br />function f():void {<br /> var n:int = numChildren;<br /> for (var i:int = 0; i < n; i++) {<br /> if () {<br /> x = horizontalGap * i;<br /> y = verticalGap * i;<br /> }<br /> }<br />}<br />Constant and variable declarations<br />TBD<br />Function declarations<br />TBD<br />Do this:<br />f(a, b)<br />''Not these:''<br />f(a,b)<br />f( a, b )<br />If the parameters have to wrap, indent the subsequent lines after the left parenthesis. Put multiple parameters per line if they fit. Otherwise, put one per line. If even one won't fit, put the first one on the second line, indented past the beginning of the function name.<br />public function foo(parameter1:Number, parameter2:String,<br /> parameter3:Boolean):void<br />public function foo(parameter1:Number,<br /> parameter2:String,<br /> parameter3:Boolean):void<br />public function aVeryLongFunctionName(<br /> parameter1:Number, parameter2:String,<br /> parameter3:Boolean):void<br />Function calls<br />TBD<br />Do this:<br />f(a, b)<br />Not these:<br />f(a,b)<br />f( a, b )<br />if statements<br />Follow the if keywords with a single space before the left parenthesis. Don't put any spaces after the left parenthesis or before the right parenthesis.<br />Do this:<br />if (a < b)<br />Not these:<br />if(a < b)<br />if( a < b )<br />if ( a < b )<br />else if ?<br />multiline ?<br />for statements<br />Follow the for keyword with a single space before the left parenthesis. Don't put any spaces after the left parenthesis or before the right parenthesis.<br />Do this:<br />for (var i:int = 0; i < n; i++)<br />Not these:<br />for(var i:int = 0; i < n; i++)<br />for( var i:int = 0; i < n; i++ )<br />for ( var i:int = 0; i < n; i++ )<br />If the for clause needs to wrap, indent the subsequent lines after the left parenthesis.<br />for (var aLongLoopVariableName:int = aLongInitialExpression;<br /> aLongLoopVariableName < aLongUpperLimit;<br /> aLongLoopVariableName++)<br />switch statements<br />Follow the switch keyword with a single space before the left parenthesis. Don't put any spaces after the left parenthesis or before the right parenthesis.<br />Do this:<br />switch (n)<br />Not these:<br />switch(n)<br />switch( n )<br />switch ( n )<br />Follow the switch keyword with a single space before the left parenthesis. Don't put any spaces after the left parenthesis or before the right parenthesis.<br />Do this:<br />switch (n)<br />{<br /> case 1:<br /> {<br /> a = foo();<br /> break;<br /> }<br /> case 2:<br /> { a = bar();<br /> break;<br /> }<br /> default:<br /> {<br /> a = blech();<br /> break;<br /> }<br />}<br />Not these:<br />switch(n)<br />switch( n )<br />switch ( n )<br />class and interface declarations<br />braces are always balanced<br />no braces around single lines<br />single statement per line<br />ASDoc<br />Property comments<br />Only document the first function of a get/set function pair for a property. The idiom for defining and documenting a property is:<br />/**<br /> * @private<br /> * The backing variable for the property.<br /> */<br />private var _someProp:Foo;<br />/**<br /> * Place all comments for the property with the getter which is defined first. <br /> * Comments should cover both get and set behavior as appropriate.<br /> */<br />public function get someProp():Foo<br />{<br /> ...<br />}<br /> <br />/**<br /> * @private<br /> */<br />public function set someProp(value:Foo):void<br />{<br /> ...<br />}<br />Also, ASDoc comments are applied to metadata tags as well as other constructs within a class so take care that your comments apply to the proper target. If you tag a property as Bindable, your property comment must precede the get function, not the Bindable metadata tag.<br />Do this:<br />[Bindable(" somePropChanged" )]<br />/**<br /> * Comments for someProp<br /> */<br />public function get someProp():Foo<br />Not this:<br />/**<br /> * Comments for someProp<br /> */<br />[Bindable(" somePropChanged" )]<br />public function get someProp():Foo<br />참고 : 컴포너트 유료사이트 - http://www.infosoftglobal.com/<br />어도브 컴포넌트 포탈<br />http://www.adobe.com/cfusion/exchange/index.cfm?s=5&from=1&o=desc&cat=186&l=-1&event=productHome&exc=15<br />구글 오픈 컴포넌트<br />http://code.google.com/p/flexlib/wiki/ComponentList<br /><참고 : 델파이의 네이밍룰을 이용해 FLEX대비><br />1. 명명 규칙<br />명명법 요지 : 변수 타입(Variable Type)의 약어를 접두어롤 표시하는 것은, FLEX의 객체 조사기(Object Inpector) 와 코드 탐색기(Code Explore) 가 리스트를 알파벳 순서로 정렬하기 때문이다. 따라서 같은 타입 별로 분류되어 많은 변수명과 컴포넌트 중에서 빠르게 찾을 수 있도록 한다.<br />2. 기본 명명 규칙<br />개요 : 낙타식 명명법 을 쓴다. <br />이름을 단어별로 첫번째 문자를 대문자로 나머지 문자를 소문자로 이름 짖는다. (ex: UserGrade, IsCertified, GroupPartName)<br />폼 파일 : 폼의 용도를 나타내는 단어 뒤에 Frm을 붙인 이름을 사용한다. 예를 들어 메인폼의 파일 이름은 MainFrm.mxml 가 된다.<br />데이터 모듈 파일 : 데어터 모듈의 용도를 나타내는 단어 뒤에 DM을 붙인 이름을 사용한다. <br />예를 들어 메인 데이터 모듈의 파일 이름은 MainDM.mxml 가 된다.<br />기본 변수와 상수 - 상수 (Constance) : 원칙적으로 대문자로 이름짖는다. (ex: MAX_STEP).                               문자열은 예외로 S 소문자 접두어를 붙인다. (ex: sXXXX)- 함수 파라미터 (Procedure Parameter) : A 대문자 접두어를 붙인다. (ex: AXXX)- 스트링 변수 (String Variable) : STR 소문자 접두어를 붙인다. (ex: strXXXX)- 배열 변수 (Array Variable) : SZ 소문자 접두어를 붙인다. (ex: szXXXX)- 숫자 변수 (Number Variable) : N 소문자 접두어를 붙인다. (ex: nXXXX)- 실수 변수  (Floating Variable) : D 소문자 접두어를 붙인다. (ex: dXXXX)- 부울린 변수 (Boolean Variable) : B 소문자 접두어를 붙인다. (ex: bXXXX)기타 타입은 타입의 첫번째 문자를 소문자로 접두어를 붙인다. (ex: Word: wXXXX)<br />변수 위치- 전역 변수 (Global Variable) : G 소문자 접두어를 붙인다. 기존이름에 추가.(ex: gstrXXX, gnXXX)- 로컬 변수 (Local Variable) : L 소문자 접두어를 붙인다. 기존이름에 추가.(ex: lstrXXX, lnXXX)<br />레코드- 레코드는 최소 기능별로 분류하여, 멤버 변수의 수가 많지 않게한다. 레코드 멤버 변수의 명명 기본규칙은변수형 접두어 없이 M 소문자 접두어를 붙인다. (ex. mXXXX)그러나 멤버 변수의 변수 타입이 중요하거나, 비슷한 이름의 변수 사이의 구분이 필요할 때는 변수형 접두어를 붙인다. (ex: mstrXXXX, mnXXXX) 또한 멤버 변수가 많구, 그룹별로 구분지어야 한다면 그룹명을 접두어로 붙인다.(ex: 유료회원, 무료회원 으로 구분할때.  mPayID, mPayPW, mFreeID, mFreePW...)<br />클래스- 클래스는 변수 기능별로 분류하여 레코드로 정의해 놓으면, 용도와 기능별로 변수 관리가 편하고 멤버변수를 줄일 수 있습니다.- 클래스 멤버 변수의 명명 기본규칙은 변수형 접두어 없이 F 대문자 접두어를 붙인다. (ex. FXXXX)- 복수개의 변수는 List 접미어를 붙인다. (s or List 둘다 좋은 접미어 인데, s 접미어는 쉽게 구분이 안된다는 이유로 List 를 추천합니다.) (ex: FPayIDList: TStringList)<br />3. 컴포넌트 명명 규칙<br />모든 컴포넌트를 명명규칙에 따라 명명하지는 않습니다. 핸들링 하는 컴포넌트만 명명법을 적용합니다. 가령 TSplitter 는 폼위에 올려놓구 쓰지만 코드에서 핸들링하는 분은 거의 없을 겁니다. 그래서 Splitter1이름을 그냥 쓰죠.. 또한 폼에 많은 TLabel을 올려놓지만, 코드에서 TLabel.Caption 에 값을 쓰는 TLabel 만lbl 접두어를 붙입니다. 써드파티 컴퍼넌트도 비슷한 원리로 명명합니다.<br />Form폼형은 접두어로 frm 을 붙인다. 때때로 TForm을 상속받은 클래스가 두개 이상일때 구분을 용이하게 합니다.(ex: frmMain)<br />Standard Tapfms        TFramemm        TMainMenupm        TPopupMenummi        TMainMenuItempmi        TPopupMenuItemlbl        TLabeledt        TEditmem        TMemobtn        TButtoncb        TCheckBoxrb        TRadioBoxlb        TListBoxcb        TComboBoxscb        TScrollBargb        TGroupBoxrg        TRadioGrouppnl        TPanelal        TActionList2. Addition Tabbbtn        TBitBtnsbtn        TSpeedButtonmedt        TMaskEditsg        TStringGriddg        TDrawGridimg        TImageshp        TShapebvl        TBevelsbx        TScrollBoxclb        TCheckListBoxspl        TSplitterstx        TStaticTextcb        TControlBarae        TApplicationEventct        TChart<br />Win32 Tabtc        TTabControlpc        TPageControlil        TImageListredt        TRichEdittbr        TTrackBarpb        TProgressBarud        TUpDownhk        THotKeyani        TAnimationdtp        TDateTimePickertv        TTreeViewlv        TListViewhdr        THeaderControlsb        TStatusBarclb        TCoolBarps        TPageScroller<br />System Tabtm        TTimerpb        TPaintBoxmp        TMediaPlayeroc        TOleContainerddcc        TDDEClientConvddci        TDDEClientItemddsc        TDDEServerConvddsi        TDDEServerItem<br />Internet Tabcs        TClientSocketss        TServerSocketwd        TWebDispatcherpp        TPageProducertp        TQueryTableProducerdstp        TDataSetTableProducerdspp        TDataSetPageProducerwb        TWebBrower<br />Data Access Tabds        TDataSourcetbl        TTableqry        TQuerydb        TDateBasesn        TSessionbm        TMatchMoveusql        TUpdateSQL<br />Data Controls Tabdbg        TDBGriddbn        TDBNavigatordbt        TDBTextdbe        TDBEditdbm        TDBMemodbi        TDBImagedblb        TDBListBoxdbcb        TDBComboBoxdbch        TDBCheckBox........<br />Dialogs Tabod        TOpenDialogsd        TSaveDialogopd        TOpenPictureDialogspc        TSavePictureDialogfd        TFontDialogcd        TColorDialogpd        TPrintDialogpsd        TPrintSetupDialogfd        TFindDialogrd        TReplaceDialog <br />