Flex best practices – Part 2: Development practices
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.
Limit code to one statement per line
Refrain from placing multiple statements on one line.
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.
Place the getter method above the setter method
When creating getter/setter methods place the getter method first.
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.
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.
Always use an access modifier for method signatures
Always use an access modifier for method signatures: public, private, protected, internal.
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.
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.
Do not use spaces to separate method names from parentheses
Strive for clean, uniform, and standardized source code.
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 ().
(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)