以 C 开头的类名 [英] Class names that start with C

查看:10
本文介绍了以 C 开头的类名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

MFC 具有以 C 开头的所有类名.例如,CFile 和 CGdiObject.有没有人看到它在其他地方使用过?是否有来自 Microsoft 的官方命名约定指南推荐这种风格?这个想法是源自 MFC 还是其他项目?

The MFC has all class names that start with C. For example, CFile and CGdiObject. Has anyone seen it used elsewhere? Is there an official naming convention guide from Microsoft that recommends this style? Did the idea originate with MFC or was it some other project?

推荐答案

在 Symbian C++ 中使用了一些类似的东西,其中的约定是:

Something a bit similar is used in Symbian C++, where the convention is that:

T 类是值",例如 TChar、TInt32、TDes

T classes are "values", for example TChar, TInt32, TDes

R 类是内核(或其他)资源的句柄,例如 RFile、RSocket

R classes are handles to kernel (or other) resources, for example RFile, RSocket

M 类是 mixin,其中包括接口(被解释为没有函数实现的 mixin).指导原则是多重继承最多应涉及 1 个非 M 类.

M classes are mixins, which includes interfaces (construed as mixins with no function implementations). The guideline is that multiple inheritance should involve at most 1 non-M class.

C 类几乎是所有其他东西,并且从 CBase 派生,其中包含一些有助于资源处理的东西.

C classes are pretty much everything else, and derive from CBase, which has some stuff in it to help with resource-handling.

HBufC 的存在主要是为了在 Symbian 论坛上生成混乱的帖子,拥有自己的前缀只是开始.H 代表嗯?",或者可能是哇,哇!你没有 STL!";-)

HBufC exists primarily to generate confused posts on Symbian forums, and having its very own prefix is just the start. The H stands for "huh?", or possibly "Haw, haw! You have no STL!" ;-)

这在精神上接近于 Apps Hungarian Notation,而不是 Systems Hungarian notation.前缀告诉您一些关于类的信息,您可以在文档中查找这些信息,但您不知道这些信息.在编程中命名任何东西的全部意义在于提供这样的提示和提醒,否则你只需将你的类称为Class001"、Class002"等.

This is close in spirit to Apps Hungarian Notation rather than Systems Hungarian notation. The prefix tells you something about the class which you could look up in the documentation, but which you would not know otherwise. The whole point of naming anything in programming is to provide such hints and reminders, otherwise you'd just call your classes "Class001", "Class002", etc.

Systems Hungarian 只是告诉您变量的类型,IMO 对此没什么好兴奋的,尤其是在像 C++ 这样的语言中,类型往往会不断重复或完全被模板参数隐藏.命名类型时的类似物是用 I 命名所有接口的 Java 实践.同样,我对此并不感到非常兴奋(标准 Java 库也没有),但如果您要为每个类定义一个接口,除了在非测试情况下实际用于多态的接口外,还需要一些方法来区分两者.

Systems Hungarian just tells you the type of a variable, which IMO is nothing to get very excited about, especially in a language like C++ where types tend to be either repeated constantly or else completely hidden by template parameters. Its analogue when naming types is the Java practice of naming all interfaces with I. Again, I don't get very excited about this (and neither do the standard Java libraries), but if you're going to define an interface for every class, in addition to the interfaces which are actually used for polymorphism in non-test situations, then you need some way to distinguish the two.

这篇关于以 C 开头的类名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆