对于理解应用程序的逻辑流,命名方案是最有影响力的一种帮助。名称应该说明“什么”而不是“如何”。通过避免使用公开基础实现(它们会发生改变)的名称,可以保留简化复杂性的抽象层。例如,可以使用 GetNextStudent(),而不是 GetNextArrayElement()。
命名原则是:选择正确名称时的困难可能表明需要进一步分析或定义项的目的。使名称足够长以便有一定的意义,并且足够短以避免冗长。唯一名称在编程上 仅用于将各项区分开。表现力强的名称是为了帮助人们阅读;因此,提供人们可以理解的名称是有意义的。不过,请确保选择的名称符合适用语言的规则和标准。
以下几点是推荐的命名方法。
AnalyzeThis(),或者对于变量的 xxK8。这样的名称会导致多义性,而不仅仅是抽象。Book.BookTitle。而是应该使用 Book.Title。CalculateInvoiceTotal()。Avg、Sum、Min、Max、Index)。CalculateInvoiceTotal),其中每个单词的第一个字母都是大写的。对于变量名,请使用 camel 大小写处理 (documentFormatType),其中除了第一个单词外每个单词的第一个字母都是大写的。Is,这意味着 Yes/No 或 True/False 值,如 fileIsFound。Flag 的术语。状态变量不同于布尔变量的地方是它可以具有两个以上的可能值。不是使用 documentFlag,而是使用更具描述性的名称,如 documentFormatType。i 或 j。For i = 1 To 7。而是使用命名常数,如 For i = 1 To NUM_DAYS_IN_WEEK 以便于维护和理解。Employee,而不是 Employees。Employee 的表中避免使用名为 EmployeeLastName 的字段。sp 前缀,这个前缀是为标识系统存储过程保留的。fn_ 前缀,这个前缀是为标识内置函数保留的。xp_ 前缀,这个前缀是为标识系统扩展存储过程保留的。GetCurrentWindowName()。ProcessSales() 的例程和名为 iProcessSales 的变量。$ 代表字符串或用 % 代表整数。软件文档以两种形式存在:外部的和内部的。外部文档(如规范、帮助文件和设计文档)在源代码的外部维护。内部文档由开发人员在开发时在源代码中编写的注释组成。
不考虑外部文档的可用性,由于硬拷贝文档可能会放错地方,源代码清单应该能够独立存在。外部文档应该由规范、设计文档、更改请求、错误历史记录和使用的编码标准组成。
内部软件文档的一个难题是确保注释的维护与更新与源代码同时进行。尽管正确注释源代码在运行时没有任何用途,但这对于必须维护特别复杂或麻烦的软件片段的开发人员来说却是无价的。
以下几点是推荐的注释方法:
格式化使代码的逻辑结构很明显。花时间确保源代码以一致的逻辑方式进行格式化,这对于您和必须解密源代码的其他开发人员都有帮助。
以下几点是推荐的格式化方法。
for (i = 0; i < 100; i++)
{
...
}
还可以使用倾斜样式,即左括号出现在行尾,右括号出现在行首,如:
for (i = 0; i < 100; i++){
...
}
无论选择哪种样式,请在整个源代码中使用那个样式。
If ... Then
If ... Then
...
Else
End If
Else
...
End If
缩进代码会产生出更容易阅读的代码,如:
If ... Then
If ... Then
...
Else
...
End If
Else
...
End If
for (i = 0; i < 100; i++)。SELECT FirstName, LastName
FROM Customers
WHERE State = 'WA'
Use the following three conventions for capitalizing identifiers.
The first letter in the identifier and the first letter of each subsequent concatenated word are capitalized. You can use Pascal case for identifiers of three or more characters. For example:
BackColor
The first letter of an identifier is lowercase and the first letter of each subsequent concatenated word is capitalized. For example:
backColor
Uppercase
All letters in the identifier are capitalized. Use this convention only for identifiers that consist of two or fewer letters. For example:
System.IO
System.Web.UI
You might also have to capitalize identifiers to maintain compatibility with existing, unmanaged symbol schemes, where all uppercase characters are often used for enumerations and constant values. In general, these symbols should not be visible outside of the assembly that uses them.
The following table summarizes the capitalization rules and provides examples for the different types of identifiers.
| Identifier | Case | Example |
|---|---|---|
| Class | Pascal | AppDomain |
| Enum type | Pascal | ErrorLevel |
| Enum values | Pascal | FatalError |
| Event | Pascal | ValueChange |
| Exception class | Pascal | WebException Note Always ends with the suffix Exception. |
| Read-only Static field | Pascal | RedValue |
| Interface | Pascal | IDisposable Note Always begins with the prefix |
| Method | Pascal | ToString |
| Namespace | Pascal | System.Drawing |
| Parameter | Camel | typeName |
| Property | Pascal | BackColor |
| Protected instance field | Camel | redValue Note Rarely used. A property is preferable to using a protected instance field. |
| Public instance field | Pascal | RedValue Note Rarely used. A property is preferable to using a public instance field. |
To avoid confusion and guarantee cross-language interoperation, follow these rules regarding the use of case sensitivity:
namespace ee.cummings;
namespace Ee.Cummings;
void MyFunction(string a, string A)
Point p and POINT p are inappropriate type names because they differ only by case.
System.Windows.Forms.Point p
System.Windows.Forms.POINT p
int Color and int COLOR are inappropriate property names because they differ only by case.
int Color {get, set}
int COLOR {get, set}
calculate and Calculate are inappropriate method names because they differ only by case.
void calculate()
void Calculate()
To avoid confusion and guarantee cross-language interoperation, follow these rules regarding the use of abbreviations:
GetWindow instead of GetWin.UI for User Interface and OLAP for On-line Analytical Processing.System.IO instead of System.Io.| AddHandler | AddressOf | Alias | And | Ansi |
| As | Assembly | Auto | Base | Boolean |
| ByRef | Byte | ByVal | Call | Case |
| Catch | CBool | CByte | CChar | CDate |
| CDec | CDbl | Char | CInt | Class |
| CLng | CObj | Const | CShort | CSng |
| CStr | CType | Date | Decimal | Declare |
| Default | Delegate | Dim | Do | Double |
| Each | Else | ElseIf | End | Enum |
| Erase | Error | Event | Exit | ExternalSource |
| False | Finalize | Finally | Float | For |
| Friend | Function | Get | GetType | Goto |
| Handles | If | Implements | Imports | In |
| Inherits | Integer | Interface | Is | Let |
| Lib | Like | Long | Loop | Me |
| Mod | Module | MustInherit | MustOverride | MyBase |
| MyClass | Namespace | New | Next | Not |
| Nothing | NotInheritable | NotOverridable | Object | On |
| Option | Optional | Or | Overloads | Overridable |
| Overrides | ParamArray | Preserve | Private | Property |
| Protected | Public | RaiseEvent | ReadOnly | ReDim |
| Region | REM | RemoveHandler | Resume | Return |
| Select | Set | Shadows | Shared | Short |
| Single | Static | Step | Stop | String |
| Structure | Sub | SyncLock | Then | Throw |
| To | True | Try | TypeOf | Unicode |
| Until | volatile | When | While | With |
| WithEvents | WriteOnly | Xor | eval | extends |
| instanceof | package | var |
| C# type name | Visual Basic type name | JScript type name | Visual C++ type name | Ilasm.exe representation | Universal type name |
|---|---|---|---|---|---|
| sbyte | SByte | sByte | char | int8 | SByte |
| byte | Byte | byte | unsigned char | unsigned int8 | Byte |
| short | Short | short | short | int16 | Int16 |
| ushort | UInt16 | ushort | unsigned short | unsigned int16 | UInt16 |
| int | Integer | int | int | int32 | Int32 |
| uint | UInt32 | uint | unsigned int | unsigned int32 | UInt32 |
| long | Long | long | __int64 | int64 | Int64 |
| ulong | UInt64 | ulong | unsigned __int64 | unsigned int64 | UInt64 |
| float | Single | float | float | float32 | Single |
| double | Double | double | double | float64 | Double |
| bool | Boolean | boolean | bool | bool | Boolean |
| char | Char | char | wchar_t | char | Char |
| string | String | string | String | string | String |
| object | Object | object | Object | object | Object |
关于 Framework 3.0
Microsoft .NET Framework 3.0(以前称为 WinFX),是用于 Windows 的新式托管代码编程模型。它将
.NET Framework 2.0 的功能和新的结构构建应用程序技术完美结合,可提供夺目的用户视觉体验、实现跨越技术边界的无缝通信,并支持广泛的业务流程。Microsoft
计划将 .NET Framework 3.0作为 Windows Vista 的一部分来提供。同时,Microsoft 也将在
Windows XP Service Pack 2 和 Windows Server 2003 Service Pack 1 中提供
.NET Framework。
下表列出了 .NET Framework 3.0 包含的若干技术。
| 技术 | 说明 |
| Windows Presentation Foundation(WPF,以前的代号为“Avalon”) | 提供用于结合 UI、文档和媒体构建下一代智能客户端应用程序的类。 |
| Windows Communication Foundation(WCF,以前的代号为“Indigo”) | 提供统一的编程模型和运行时,用以构建面向服务的应用程序。 |
| Windows Workflow Foundation (WF) | 提供编程模型、引擎和工具来构建支持工作流的应用程序,以进行业务流程建模。 |
| Windows CardSpace(以前的代号为“InfoCard”) | 通过使用个人标识信息,简化和改善在线工作安全性。 |
| Microsoft .NET Framework 2.0 | 提高了构建 Windows 和基于 Web 的应用程序的效率。 |
所有代表新组件(WPF、WF、WCF 和 CardSpace)的类均属于系统命名空间。.NET 平台的核心类,如公共语言运行时 (CLR) 和基类库 (BCL),均保留了 .NET Framework 2.0 中的原样。

网址:
1.Windows® Workflow Foundation安装说明