Sean is a highly sought after Flex developer and consultant with extensive ActionScript programming experience, including more than five years developing for the Flash platform and over a decade of experience designing and developing desktop and web based applications. Business owner, technical author, blogger and Adobe Flex/AIR enthusiast, Sean is an Adobe Flex Developer Community Champion and the creator of the ActionScript Cheatsheets. Sean has posted 2 posts at DZone. View Full User Profile

Flex best practices – Part 2: Development practices

03.16.2009
| 55812 views |
  • submit to reddit
Best practices for methods

checkmark Include a verb in method names

Methods usually perform an action of some kind on an object of some kind. Use the name of the action in the method name; for example, saveUser or parseXML.

checkmark Limit code to one statement per line

Refrain from placing multiple statements on one line.

checkmark Group methods in a class by functionality

When possible, group the methods in your classes by responsibility instead of scope. Related methods should be placed together to improve code understandability and readability.

checkmark Place the getter method above the setter method

When creating getter/setter methods place the getter method first.

checkmark Comment each method using ASDoc style comments

In your comments, explain the reasoning behind the need of the method and describe the usage details for classes that might be calling the method. Explain the "why" instead of restating what the method does. See the example ASDoc comment in the Commenting ActionScript source code for ASDoc section of this article.

checkmark Always provide a return type even if it is void (returns nothing) or * (any type)

Provide a return type for all of your methods. A method's purpose can be better understood by looking at the return type.

checkmark Always use an access modifier for method signatures

Always use an access modifier for method signatures: public, private, protected, internal.

checkmark Specify types for method arguments

Provide a type for all method arguments. This can help developers as they write code that will call the method.

checkmark Name the arguments of event handlers "event"

This helps to differentiate the event handlers from other code in your application. Other standard argument names are e and evt. Like most standards just agree on one way of doing things and stand by it.

checkmark Do not use spaces to separate method names from parentheses

Strive for clean, uniform, and standardized source code.

checkmark Use blank spaces to separate keywords from parentheses

When setting up if, for, case and while statements, place a blank space between the keyword and the parenthesis; for example: while ().

Published at DZone with permission of its author, Sean Moore.

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)