Flex best practices – Part 2: Development practices
Use meaningful variable names
One-character variable names should generally be avoided. Abbreviated variable names should also be avoided.
Choose descriptive variable names
The compiler will optimize these for you anyway, so the length does not affect file size. Well named variables and functions will make the code easier to read and require the developer to write less documentation.
One variable declaration per line of source code
Try to avoid multiple variable declarations and assignments in a single line of code. Developers can easily overlook a declaration when there are several on a single line.
Separate each variable declaration with a blank line
To improve source code readability, each variable should have an ASDoc comment directly above it; the variable declaration should follow the comment, and a blank line should follow the declaration.
Comment each variable using ASDoc style comments
Describe the reasoning for the variable. Try not to restate the purpose of the variable, instead strive to describe how it is used. See the example ASDoc comment in the Commenting ActionScript source code for ASDoc section of this article.
Avoid the generic name "object"
Avoid using "object" in your variable names. Instead, give more meaning to the identifier.
Always strongly type your variables
Even if the type is * (no type), strongly typing your variable can help show the intention of the variable. The type can help to convey the variable's use and purpose. A strongly typed variable has a predetermined data type and can contain data of that type only (unless the type is changed).
Prefix Boolean variable names with "can", "is", or "has"
This practice can help to quickly identify and differentiate the Boolean variables from other variable types; for example: canAnimate, isConnected, or hasChildren.
Constant variables should be in all CAPS with each word separated by an underscore; for example: REMOTE_SERVER_URL, APPLICATION_ID, and DISCLAIMER_TEXT.
Constant variables are values that will not change during the execution of the application. By capitalizing them you can differentiate constants from regular (non-constant) variables.
Match constant string variable names to their contents
If the constant is a string, then match the constant variable name to the string contents. For example, the string "dataEvent" should be in a constant variable named "DATA_EVENT".
Prefix variables with underscores for getter/setters
Prefix variables with an underscore if they will be modified through getter/setter methods.
(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)