[Framework Design Guideline]命名规范(1)

 

1. 命名大小写规则

Capitalization Rules for Identifiers

Use PascalCasing for namespace, type, and member names consisting of multiple words.

Use camelCasing for parameter names.

Capitalizing Acronyms

Capitalize both characters of two-character acronyms, except the first word of a camel-cased identifier.

例如: System.IO

          public void StartIO(Stream ioStream)

Capitalize only the first character of acronyms with three or more characters, except the first word of a camel-cased identifier.

例如: System.Xml

          public void ProcessHtmlTag(string htmlTag)

Capitalizing Compound Words and Common Terms

一些组合词和习惯用语按照既定的习惯来进行大小写的判定。比如:ok,在Pascal Casing下写成 Ok,在Camel Casing下写成ok。

Case Sensitivity

Names cannot differ by case alone.

 

2. 一般的命名惯例

Word Choice

Choose easily readable identifier names.

Favor readability over brebity.

Don’t use underscores, hyphens, or any other non-alphanumeric characters.

     这个规则都是针对public和protected的成员,针对private field,可以考虑使用m_前缀。针对静态成员可以考虑使用s_前缀。

Avoid using identifiers that conflict with keywords of widely used prgramming languages.

Using Abbreviations and Acornyms

Don’t use abbreviations or contractions as part of identifier names.

比如: 方法名GetWindow()比GetWin()要好

Don’t use any acronyms that are not widely accepted, and even if they are, only when necessary.

Avoiding Language-Specific Names

Use semantically interesting names rather than language-specific keywords ofr type names.

比如: GetLength is a better name than GetInt.

Use a generic CLR type name, rather than a language-specific name.

比如: ToInt64() 比 ToLong()要好。

Use a common name, such as value or item, rather than repeating the type name.

Naming New Version of Existing APIs

Use a name similar to the old API when creating new versions of an existing API.

For example: AppDomain and AppDomainSetup

Prefer adding a suffix rather than a prefix to indicate a new version of an existing API.

Consider using a brand new, but meaningful identifier, instead of adding a suffix or a prefix.

Use a numberic suffix to indicate a new version of an existing API, particularly if the existing name of the API is the only name that makes sense and if adding any meaningful suffix is not an apropriate option.

Don’t use the “Ex”( or a similar) suffix for an identifier to distinguish it from an earlier of the same API.

比如:

   [Obsolete("this type is obsolete. ...")]
    public class Car { }

    //new API
    public class CarEx { } //the wrong way
    public class CarNew { } //the wrong way
    public class Car2 { } //the right way
    public class Automobile { } //the right way

Use the “64” suffix when introducing version s of APIs that operate on a 64-bit integer instead of 32-bit integer.

posted @ 2013-05-14 22:38  猪小广  阅读(375)  评论(0编辑  收藏  举报