Skip to content

Instantly share code, notes, and snippets.

@claus
Created December 11, 2009 03:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save claus/253969 to your computer and use it in GitHub Desktop.
Save claus/253969 to your computer and use it in GitHub Desktop.
// packages, classes and contructors never cuddle
package
{
public class MyClass
{
public function MyClass()
{
// code
}
}
}
// everything else (like class methods) cuddles, within reason
protected function myFunction():void {
}
// one line code blocks are always enclosed by { .. }
// never do something like this: while (expression) i++
// extreme-cuddling sometime makes sense, if code blocks are trivial
while (expression) { i++; }
while (expression) {
i++;
}
if (expression) { i++; } else { i--; }
if (expression) {
i++;
} else {
i--;
}
// switches sometimes cuddle (if the code blocks are trivial)
switch (myVar) {
case 1: myString = "1"; break;
case 2: myString = "2"; break;
default: myString = "3"; break;
}
// switches sometimes do not cuddle (if the code blocks are more verbose)
switch (myVar)
{
case 1:
myString = "1";
// more
break;
case 2:
myString = "2";
// more
break;
default:
myString = "3";
// more
break;
}
// getter/setter stubs often extreme-cuddle
public function get myVar():String { return _myVar; }
public function set myVar(value:String):void { _myVar = value; }
// expressions are always surrounded by spaces
var myVar:Number = Math.round(1 / myOtherVar) + 42;
// function arguments/types are never surrounded by spaces
// space only after commas and around equal signs (see expressions)
function myFunction(arg1:String, arg2:int, arg3:Number):void
function myFunction(arg1:String = "default"):void
// array initialization with few values:
var myArr:Array = [ "value 1", "value 2" ];
// array initialization with more values:
var myArr:Array = [
"value 1",
"value 2",
"value 3",
// .. more
];
// object initialization with few values:
var myObj:Object = { a: "value 1", b: "value 2" };
// object initialization with more values:
var myObj:Object = {
a: "value 1",
b: "value 2",
c: "value 3",
// .. more
};
// multi dimensional vector initialization:
var myVector:Vector.<Vector.<Number>> =
Vector.<Vector.<Number>>([
Vector.<Number>([ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ]),
Vector.<Number>([ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ])
]);
// inline comments look like this
// never ever use /* */ style for inline comments
// only use /* */ style for asdocs stuff
// (and to comment out code during development)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment