After having work on some big projects using very strong naming conventions, I recognized that despite of the boring aspect to “force yourself” using a specific convention, it is much more readable when you read code written by someone else.
Here are listed the choices I made while developing Sandy, and which is the one you'll have to use for your contributions.
All classes name are written in English.
They start with a capital letter, and basically use the Java naming convention.
Interfaces shall start with a capital I.
Abstract classes (even in not native in ActionScript) shall start with a capital A.
Variables also require a specific naming convention.
Scope information:
The exception is for the public class members, that don't use any specific prefix.
Type information:
Names : Once the prefix written, comes the real name of the variable. Even if the actionscript code is faster at execution time when variables names are shorter, we recommend to use explicit names. Sure the shoter explicit name is better.
The attention required for the variable name also depends on where it is used. The more critical and complex location, the more complete and explicit the variable name should be.
Example :
var l_nMyNumber:Number = 0.33;
var l_aMyArray:Array = [1,2,5,7,12,19];
class MyClass { private var m_mcContainer:MovieClip; public var version:Number; public static function main( p_mcRoot:MovieClip ):Void { var l_oInstance:MyClass = new MyClass( p_mcRoot ); } public function MyClass( p_mcRoot:MovieClip ) { m_mcContainer = p_mcRoot; version = 2.0; } }
Sandy conventions also require to always specify the whole scope of the variable/method in the classes definition.
Example :
Bad declaration of MyClass example
class MyClass { private var m_mcContainer:MovieClip; var version:Number; static function main( p_mcRoot:MovieClip ):Void { var l_oInstance:MyClass = new MyClass( p_mcRoot ); } function MyClass( p_mcRoot:MovieClip ) { m_mcContainer = p_mcRoot; version = 2.0; } }
In addition to the naming convention, Sandy developers shall use the following development rules :
Correct example :
function test( p_bMyBoolean:Boolean ):void { if( p_bMyBoolean ) { ;// Do something here } else { ;// Do something else } }
Wrong example :
function test( p_bMyBoolean:Boolean ):void{ if( p_bMyBoolean ){ ;// Do something here }else { ;// Do something else } }