Class names that start with C(以 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 开头的类名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:以 C 开头的类名


基础教程推荐
- 如何检查GTK+3.0中的小部件类型? 2022-11-30
- 静态库、静态链接动态库和动态链接动态库的 .lib 文件里面是什么? 2021-01-01
- 常量变量在标题中不起作用 2021-01-01
- 我有静态或动态 boost 库吗? 2021-01-01
- 如何在 C++ 中初始化静态常量成员? 2022-01-01
- 在 C++ 中计算滚动/移动平均值 2021-01-01
- 如何将 std::pair 的排序 std::list 转换为 std::map 2022-01-01
- 这个宏可以转换成函数吗? 2022-01-01
- C++结构和函数声明。为什么它不能编译? 2022-11-07
- 如何通过C程序打开命令提示符Cmd 2022-12-09