六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 419|回复: 0

【转载】Flex SDK coding conventions and best practices

[复制链接]

升级  40%

4

主题

4

主题

4

主题

童生

Rank: 1

积分
20
 楼主| 发表于 2013-2-8 01:05:09 | 显示全部楼层 |阅读模式
文章引自http://opensource.adobe.com/wiki/display/flexsdk/Coding+Conventions
有网友做了翻译,链接如下http://www.flashas.net/html/Flex/20080813/3579.html

有空翻译下
 
Flex SDK coding conventions and best practices


 
 

<span class="Apple-style-span" style="color: #000000; text-indent: 0px; white-space: normal; letter-spacing: normal; border-collapse: separate;"><span class="Apple-style-span" style="font-size: 12px; line-height: 16px; font-family: Verdana, arial, sans-serif;">Introduction

This document lays out the coding standards for writing open-source Flex framework components in ActionScript 3. Adhering to these standards makes the source code look consistent, well-organized, and professional.
Some of these standards are completely arbitrary, since there is not always a “best way” to code. Nevertheless, in the interest of consistency, all commits to the Flex SDK project will be expected to follow these conventions.
 

<span class="Apple-style-span" style="color: #000000; text-indent: 0px; white-space: normal; letter-spacing: normal; border-collapse: separate;"><span class="Apple-style-span" style="font-size: 12px; line-height: 16px; font-family: Verdana, arial, sans-serif; text-align: left;">
[table=98%][tr][td=1,1,80%]Naming

Choosing good names is critical to creating code that is easy to use and easy to understand. You should always take the time to think about whether you have chosen the right name for something, especially if it is part of the public API.
Our naming standards are mostly consistent with those of ECMAScript and Flash Player 9.
Abbreviations

Avoid them as a general rule. For example, calculateOptimalValue() is a better method name than calcOptVal().
Being clear is more important than minimizing keystrokes. And if you don't abbreviate, developers won't have to remember whether you shortened a word like “qualified” to “qual” or “qlfd”.
However, we have standardized on a few abbreviations:

  • acc for accessibility, as in ButtonAccImpl
  • auto for automatic, as in autoLayout
  • auto for automatic, as in autoLayout
  • eval for evaluate, as in EvalBindingResponder
  • impl for implementation, as in ButtonAccImpl
  • info for information, as in GridRowInfo
  • num for number of, as in numChildren
  • min for minimum, as in minWidth
  • max for maximum, as in maxHeight
  • nav for navigation, as in NavBar
  • regexp for regular expression, as in RegExpValidator
  • util for utility, as in StringUtil
This list probably does not include all abbreviations that are currently in use. If you're considering using an abbreviation that isn't listed here, please search the source code to determine whether it is already in use. If you don't find it, think twice about whether abbreviating is really appropriate.
Occasionally we are (deliberately) inconsistent about abbreviations. For example, we spell out “horizontal” and “vertical” in most places, such as horizontalScrollPolicy and verticalScrollPolicy but we abbreviate them to H and V in the very-commonly-used container names HBox and VBox.
Acronyms

Various acronyms are common in Flex, such as AIR, CSS, HLOC, IME, MX, MXML, RPC, RSL, SWF, UI, UID, URL, WSDL, and XML.
An acronym is always all-uppercase or all-lowercase (e.g., SWF or swf, but never Swf). The only time that all-lowercase is used is when the acronym is used by itself as an identifier, or at the beginning of an identifier, and the identifier should start with a lowercase letter. See the rules below for which identifiers should start with which case.
Examples of identifiers with acronyms are CSSStyleDeclaration, IUID, uid, IIME, and imeMode.
Word boundaries

When an identifier contains multiple words, we use two ways of indicating word boundaries: intercaps (as inLayoutManager or measuredWidth) and underscores (as in object_proxy). See the rules below for which method to use.
Sometimes it isn't clear whether a word combination has become its own single word, and we are unforunately inconsistent about this in some places: dropdown, popUp, pulldown.
Follow the acronym-casing rules even in the rare case that two acronyms must be adjacent. An example (which isn't actually in use) would be something like loadCSSURL(). But try to avoid such names.
Type-specifying names

If you want to incorporate the type into the name, make it the last “word”. Don't use the old ActionScript 1 convention of concatenating abbreviated type suffixes such as _mc to indicate type. For example, name a border Shape border,borderSkin, or borderShape, but not border_mc.
Often, the best name for an object is simply the same as its type, with different casing:
<div class="preformatted panel" style="font-size: 11px; margin: 0px 10px 10px; line-height: 13px; font-family: Courier; border: #3c78b5 1px dashed;"><div class="preformattedContent panelContent" style="background-color: #f0f0f0; padding: 5px;">var button:Button = new Button();
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表