Archived

This topic is now archived and is closed to further replies.

antareus

CClassname

Recommended Posts

I know this is a religious debate for some people, but why CClassname? I''ve read many rants on the net that agree with the fact that MS chose it to use in MFC so it''d stand out, but when everyone uses it, it loses value. It seems rather redundant to me and I read so many posts that have it, so I just had to know what the rationale is behind it.

Share this post


Link to post
Share on other sites
It becomes somewhat more useful when you want to clearly distinguish between classes and interfaces.


Don''t listen to me. I''ve had too much coffee.

Share this post


Link to post
Share on other sites
I use it just to distinguish between e.g. classes and enums (class CUnit & enum EUnit [although i tend to say enum EUnitType]). I know people will say that i should name my classes better, but i still do it this way.
I also use hungarian notation to determine what type a variable is without having to find its declaration and to shorten identifier names (e.g. pszBuffer instead of ptrStringBuffer), so i guess prefixing the ''C'' is part of hungarian notation.

[HTTP 500 x3]

2p

Share this post


Link to post
Share on other sites
quote:
Original post by Sneftel
It becomes somewhat more useful when you want to clearly distinguish between classes and interfaces.


Can''t you just prefix an I to it like "iSocket" or "ISocket" (if you hate Apple ). That is a useful naming convention I think. Seems like the C is extraneous.

Share this post


Link to post
Share on other sites
Perhaps we ought to prefix all function names with fn? Oh, wait, I can tell which identifiers are function names because of the context in which they are used:


  
void fnAFunctionName () {}
class CAClassName {};
 
int main ()
{
CAClassName someObject;
fnAFunctionName ();
}


Gosh, it looks like I''ll have to find another way to make work.

Share this post


Link to post
Share on other sites
quote:
Original post by antareus
Can''t you just prefix an I to it like "iSocket" or "ISocket" (if you hate Apple ). That is a useful naming convention I think. Seems like the C is extraneous.


i is int! ;p

enum enEnumeration { one=1, two, three };
class CBanana;
int iFrogCount;
struct Apple sFruit;
typedef void tFruit;
unsigned short usFiddlers;
unsigned long ulCucumbers;
void * vpFrog;
long * lpMoose;

class Foo
{
public:
unsigned short* m_uspUshortPointer;
};

and so on.
ITS RELIGION!



What does God want?
Does God want goodness or the choice of goodness?
Is a man who chooses the bad perhaps in some way better than a man who has the good imposed upon him?

Share this post


Link to post
Share on other sites
quote:
null_pointer: Ah, but what about:


That is exactly my point. You can isolate any little bit of code and make an argument that Hungarian Notation will help because it attaches extra type information to most identifiers; however, the argument is flawed. Even if you attach "fn" prefix to function pointer typedefs, you still have no knowledge of what that function actually does. You should not be working on code you do not understand in the first place. It is generally more effective to improve your coding skills by learning to choose more clear and concise identifiers than it is to mutilate the code.

Share this post


Link to post
Share on other sites
I wonder if those who use C prefix also use it in templates.

  template <class CIterator>
...

Well, the obvious problem is that iterator might be a basic type as well as a class.

Share this post


Link to post
Share on other sites
I''ll throw in my two cents. Its all style, true, but Hungarian notation can be abused. Personally I only use:

int* pMyInt = new int; //remind me to use delete([]) and -> only
int m_classInt; //this is local to the class

But I might try _classInt to see if that is prettier

Share this post


Link to post
Share on other sites
My preference is to prefix variables to indicate scope:


int g_globalVariable;

class MyClass
{
int m_memberVariable;
};


This is handy for passing constructor arguments that have the same name as member variables.

One problem with hungarian type prefixes is that nobody seems to use the same prefix for the same data type. Examples:


unsigned int uMyUnsignedInteger;
unsigned int uiMyUnsignedInteger;
unsigned int nMyNumber;
char* pcMyPointerToChar;
char* strMyString;
char* szMyString;
char* pszMyPointerToString;
char* lpszMyLongPointerToString;


Catch my drift?

Having said that, I would be inclined to use hungarian in an MFC application for the sake of consistency. But where possible, I avoid it like the plague.

Share this post


Link to post
Share on other sites
Well, let's just go crazy on the datatype names.


    
#include <iostream>

using namespace std;

typedef int byte4DT;
typedef char byte1DT;
typedef float byte4DTF;

struct str_UCT_mySTRUCT
{
byte4DT b4dt_myAge;
byte1DT b1dt_myName[15];
byte4DTF b4dtf_myFloat;
};

int main()
{
str_UCT_mySTRUCT strUCTmySTRUCT_Person;

cout << "Enter my name: ";
cin >> strUCTmySTRUCT_Person.b1dt_myName;
cout << "Enter my age: ";
cin >> strUCTmySTRUCT_Person.b4dt_myAge;
cout << "Enter a decimal: ";
cin >> strUCTmySTRUCT_Person.b4dtf_myFloat;

return 0;
}


For anyone who cares, this was a poorly executed joke that took about 15 minutes of my time.


"aut viam inveniam aut faciam " - I will either find a way or make one.

MoonStar Projects

[edited by - Ronin Magus on December 27, 2002 11:40:12 AM]

Share this post


Link to post
Share on other sites