Symbian命名规则(翻译)(转)

00Naming conventions命名规则


Overview

Applications on the Symbian platform use a standard set of conventions to name their classes, structs, variables, functions, macros, enumerations, and constants. This topic explains the meaning of these conventions.

symbian平台上的应用程序使用一系列的标准习惯来命名他的类,结构体,变量,函数,宏,枚举类型和常量。本章将介绍这些规则的意义。

Class names

Most class names are formed with a prefix letter C, T, R, or M. Briefly, the meaning of these is as follows:

大部分类使用前缀C, T, R, M。简单意义如下:

· C: heap-allocated classes, that are derived from a base class CBase

· C 堆栈分配类,从CBase类继承

· T: value classes, that do not own any external object

· T: 变量类,不包含外部对象

· R: resource classes, that contain handles to a real resource which is maintained elsewhere

· R:资源类,包含指向实际存在资外部源的句柄

· M: interface classes, that define abstract protocol definitions that are implemented by derived classes

· M: 界面类,定义了一些虚函数,由继承的类来实现

For a detailed discussion on the meaning of these prefixes, see Class types.

可以参照Class types

Classes that consist solely of static member functions have no prefix letter. Beyond the prefix, the class name is usually a noun that indicates the purpose of the class.

全部由静态成员函数的类没有前缀字母。在前缀前,一般使用名词来表示类的用途。

Struct names

Structure types are considered as similar to T classes, as they should not own external objects, and are normally given names beginning with T (although some begin with S).

结构体类型类似T类。因为他们也不包含外部对象,同时一般也使用T前缀(也有一些使用S

Variable names变量名

Member variables’ names begin with i, e.g. iMember. This makes it easy to check that certain cleanup-related rules are being obeyed. Arguments’ names begin with a, e.g. aControl or aIndex. Local variables’ names have no initial letter. Global variables are usually avoided, but when used, their names begin with a capital letter.

成员变量名称以i打头,例如iMember。这样易于检查特定的清除相关的规则。自变量命名以a开头,例如aControl, aIndex。局部变量没有首字母。全局变量通常来说是禁止使用的,但一旦使用,他们使用大写字母做开头。

Symbian does not use Hungarian or any notation which attempts to include the variable type in its name: such notations are ugly, and become impossible to manage when there are several hundred classes in the system. They are irrelevant anyway: functions are usually so short that it is easy to see the types of variables defined in them, and class browsers provide a quick way to find the types of class members.

Symbian不使用匈牙利或其他符号的命名法,因为这样的命名方式难看,当有成百的函数在系统中时不容易管理。总之他们是不相关的:函数一般都很短并容易看出其内部定义的变量类型。而且类浏览器提供一个快速的方法来查询个中类成员类型。

Function names函数命名

Functions’ names indicate what they do. They are usually verbs. One exception is “getter” functions: for a function which returns the value of a member variable, the function name is usually the name of the variable, without the leading i:

函数名称暗示了他们是做什么的。一般来说都是动词。一个特例是”getter”函数:对于返回内部成员变量的函数,他的名称一般使用去掉首字母i的该变量名称:

inline RWindow& Window() const { return iWindow; };

A corresponding “setter” function would include the word Set, e.g. SetWindow().

对应”setter”的函数应该包含Set,例如SetWindo()

To terminate functions because of error conditions, the Symbian platform does not use standard C++ exception handling, but its own system called leaving (see Cleanup Support Overview). Any function that might leave has a name ending in ...L(). This makes the fundamental process of checking for errors easier. The new (ELeave) function might also leave. The fundamental leaving function is User::Leave(). Any function that contains any of these, and does not trap them, might itself leave, and should be coded with a trailing L in its name. If a function calls another which might leave, then its name should have the L suffix also.

由于错误而结束函数的时候,Symbian系统不使用标准的C++错误处理方式,而是用他自己的系统命令leaving(参照Cleanup Support Overview)。任何可能退出的函数都有一个尾字母…L()

Associated with the leaving mechanism, is the cleanup stack, which allows memory allocated on the heap to be recovered when a leave occurs. An allocation or construction function which places data on the cleanup stack ends with ...LC(). For instance, many new, PushL(), ConstructL() sequences are encapsulated in a NewLC() function:

结合退出机制的是堆栈清理。他允许当leave发生的时候,堆栈中被申请的内存被恢复。一个将数据防入cleanup堆栈的申请或构造函数以…LC()结尾。例如,很多new, PushL(), ConstructL()的顺序被封装入NewLC()函数。

CS* s=CS::NewLC(p1, p2);

This allocates the object, initialises it, and leaves it on the cleanup stack. This process may leave (if only through the PushL()!), so such functions always include an L, and are therefore ...LC().

申请对象,初始化并压入栈顶。这个过程有可能意外退出(只用通过PushL()!),所以着类函数总包含一个L…..LC()也一样.

A function which takes ownership of its object and destroys it has a name ending in ...D(). An example is the UI framework dialog protocol:

一个函数拥有他的对象并销毁的时候,使用….D()结尾。一个例子是UIframework对话框:

CEikDialog* dialog=new (ELeave) CBossSettingsDialog;
if (dialog->ExecuteLD(R_BOSS_SETTINGS_DIALOG))
{
// handle successful settings
}

The ExecuteLD() function includes second-phase construction, execution of the dialog and then destruction.

ExecuteLD()函数包含第2级构造,对话框执行和销毁。

Macro names

Macro names are all capitalised, with underscores to separates words.

宏的命名都是大写字母,并结合下划线分割字母。

Enumeration names

Enumerations are named as follows:

枚举类型的命名规则如下:

· as enumerations are types, they have the T prefix

· 枚举类型使用T前缀

· enumeration members have the prefix E

· 枚举成员变量使用E前缀

· type and members should have a meaningful, unambiguous name

· 类型和成员使用有意义,明确的名称

Enumerations should be scoped within the relevant class, so as not to pollute the global name space.

枚举类型应该在相关的类范围内有效,从而不污染整个命名空间

An example of the declaration and use of an enumeration is as follows:

一个枚举类型的定义例子如下:

class TDemo
{
public:
enum TShape {EShapeRound, EShapeSquare};
};

TDemo::TShape shape=TDemo::EShapeSquare;

Constant names

Names of constants have a prefix K. For example,

常量使用K前缀,例如

const TInt KMaxNameLength=0x20;


来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/10294527/viewspace-126282/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/10294527/viewspace-126282/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值