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.

Table of Contents

Abbreviations

Avoid them as a general rule. For example, calculateOptimalValue() is a better method name than calcOptVal(). 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”.

These are abbreviations commonly used, if Nightspade developers wish to add another abbreviation, discuss with other developers first.

acc for accessibility, as in ButtonAccImpl
auto for automatic, as in autoLayout
eval for evaluate, as in EvalBindingResponder
impl for implementation, as in ButtonAccImpl
info for information, as in GridRowInfo
num for number of, as in numChildren
min for minimum, as in minWidth
max for maximum, as in maxHeight
nav for navigation, as in NavBar
regexp for regular expression, as in RegExpValidator
util for utility, as in StringUtil

Acronyms

Various common acronyms: AIR, CSS, HLOC, IME, MX, MXML, RPC, RSL, SWF, UI, UID, URL, WSDL, and XML.

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. Examples are CSSStyleDeclaration, IUID, uid, IIME, and imeMode.

Word boundaries

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).

Type-specifying names

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.

Often, the best name for an object is simply the same as its type, with different casing:

1
var button:Button = new Button();

Package names

Start them with a lowercase letter and use intercaps for subsequent words: controls, listClasses.

Package names should always be nouns or gerunds (the -ing noun form of a verb), not verbs, adjectives, or adverbs.

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.

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.

File names

For importable APIs, the file name must be the same as the public API inside. e.g. Button.as

Start the names of individual asset files with a lowercase letter and use underscores between words: icon_align_left.png

Interface names

Start them with ‘I’ and use intercaps for subsequent words: IList, IFocusManager, IUID.

Class names

Start them with an uppercase letter and use intercaps for subsequent words: Button, FocusManager, UIComponent.

Name Event subclasses FooBarEvent.

Name Error subclasses FooBarError.

Name utility classes FooBarUtil (not FooBarUtils; the package is plural but the class is singular).

It is common to name a base class FooBarBase: ComboBase, DateBase, DataGridBase, ListBase.

Event names

Start them with a lowercase letter and use intercaps for subsequent words: “move”, “creationComplete”.

Enumerated values for String properties

Start them with a lowercase letter and use intercaps for subsequent words: “auto”, “filesOnly”

Constant names

Use all uppercase letters with underscores between words: OFF, DEFAULT_WIDTH.

The words in the identifier must match the words in the constant value if it is a String:

1
public static const FOO_BAR:String = "fooBar";

Property (variable and getter/setter) names

Start them with a lowercase letter and use intercaps for subsequent words: i, width, numChildren.

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. For more than double loops, try k,l and o,p for upper limit

Try to minimize nested loop numbers, since it is heavy process.

1
2
3
4
5
6
7
for (var i:int = 0; i < n; i++)
{
    for (var j:int = 0; j < m; j++)
    {
        ...
    }
}

Use p (for “property”) for a for-in loop variable:

1
2
3
4
for (var p:String in o)
{
    ...
}

Storage variable names

Give the storage variable for the getter/setter foo the name _foo. Class variables do not need underscore.

Method names

Start them with a lowercase letter and use intercaps for subsequent words: measure(), updateDisplayList().

Method names should always be verbs.

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 namedfindFooBar(), calculateFooBar(), determineFooBar(), etc. to suggest this, rather than being a getter.

Event handler names

Event handlers should be named by concatenating “Handler” to the type of the event: mouseDownHandler().

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().

Argument names

Use value for the argument of every setter:

1
2
3
4
5
6
7
8
9
10
11
// Do this:
public function set label(value:String):void
 
// Not this:
public function set label(lab:String):void
 
// Or this:
public function set label(labelValue:String):void
 
// Or this:
public function set label(val:String):void

Use event (not e, evt, or eventObj) for the argument of every event handler:

1
protected function mouseDownHandler(event:Event):void

for other argument of method, start them with a lowercase letter and use intercaps for subsequent words.