05.05
如果你是一個 Flex / ActionScript 3.0 程式設計師,你會常常思考怎樣設計程式佈局會比較好,如何命名會比較洽當嗎?那這篇一定值得你閱讀看看。

當你在想的時候,又不知道要去參考哪一個編碼規則,如果你是一個 Flex / ActionScript 3.0 程式設計師,那麼不如參考Adobe的編碼規則,因為至少是個有公信力的作法,而且如果連 Adobe 本身都規則都不好了,那 Flex 應該可以丟一邊去了。
廢話不多說,有興趣的人自己去看一看:
http://opensource.adobe.com/wiki/display/flexsdk/Coding+Conventions
有幾個有意思且大家常犯的錯誤規則我幫大家HighLight出來:Don’t use unnecessary parentheses with common operators such as +, -, *, /, &&, ||, <, <=, >, >=, ==, and !=.
Do this:
var e:Number = a * b / (c + d);
Not this:
var e:Number = (a * b) / (c + d);
And this:
var e:Boolean = a && b || c == d;
Not this:
var e:Boolean = ((a && b) || (c == d));
The precedence rules for other operators are harder to remember, so parentheses can be helpful with them.
寫的時候腦經要很清楚啊~
Only document the first function of a get/set function pair for a property. The idiom for defining and documenting a property is:
/** * @private * The backing variable for the property. */
private var _someProp:Foo;
/** * Place all comments for the property with the getter which is defined first. * Comments should cover both get and set behavior as appropriate. */
public function get someProp():Foo { ... }
/**
* @private
*/
public function set someProp(value:Foo):void { ... }
Also, ASDoc comments are applied to metadata tags as well as other constructs within a class so take care that your comments apply to the proper target. If you tag a property as Bindable, your property comment must precede the get function, not the Bindable metadata tag.
Do this:
[Bindable("somePropChanged")]
/* * * Comments for someProp */
public function get someProp():Foo
Not this:
/* * * Comments for someProp */
[Bindable("somePropChanged")]
public function get someProp():Foo
我也是常用Not this的寫法啊~
很有意思,雖然還不至於要封為聖經,但是卻可以好好參考一下。
相關文章:
文章內容由宋志峰[ANISTAR]撰寫,引用分享請以鏈結形式註明出處與原始作者。


No Comment.
Add Your Comment