Class names that start with C

前端 未结 12 1917
被撕碎了的回忆
被撕碎了的回忆 2020-12-20 13:44

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 Mic

相关标签:
12条回答
  • 2020-12-20 14:13

    Years ago naming convention is crucial to help identifying the class, type of even the grouping of the class. Dont forget back then there was no namespace and no/limited intellisense available. C is a form of Hungarian notation but certainly made popular by MFC. Borland and Delphi was using T - as prefix for Type

    0 讨论(0)
  • 2020-12-20 14:16

    When writing applications that use the Qt libraries, we use a naming convention that distinguishes classes that are directly or indirectly derived from QObject from classes that aren't. This is useful because you can tell from the class name whether or not it supports signals/slots, properties, and all the other goodies that come from QObject.

    0 讨论(0)
  • 2020-12-20 14:17

    I can't answer all your questions, but as far as I know, it's just to distinguish the MFC classes from other classes -- a form of Hungarian Notation.

    Interestingly, it's apparently controversial not just outside MS, but inside as well.

    0 讨论(0)
  • 2020-12-20 14:18

    It's evil. Don't use Hungarian Notation for anything but abstracted things.

    For instance, btnSubmit is ok to describe a button named Submit(which would have an accompanying lblSubmit for the label next to the button)

    But things like CMyClass for Class and uiCount for unsigned integer named count does not help programmers and just leads to extra wasteful typing.

    0 讨论(0)
  • 2020-12-20 14:19

    While MFC and lots of software written for Windows used the "C" convention for classes, you generally don't find the latter in software written for UNIX platforms. I think it was a habit very strongly encouraged by Visual C++. I remember that Visual C++ 6.0 would prefix a "C" to any classes that one created with the class wizard.

    0 讨论(0)
  • 2020-12-20 14:22

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

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

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

    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 classes are pretty much everything else, and derive from CBase, which has some stuff in it to help with resource-handling.

    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!" ;-)

    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 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.

    0 讨论(0)
提交回复
热议问题