I really don't understand why everyone prepends their classes with "C". What are your thoughts about this practice?
Printable View
I really don't understand why everyone prepends their classes with "C". What are your thoughts about this practice?
C stands for "class" in the class name. However, borland VCL uses T letter which stands for "type" evidently. You can or cannot adopt any prepending letter - nobody could force you to do it (except your employer I suppose :))
I've heard the "C stands for class" and "T stands for type" theory before. If you think about it, if you're declaring a variable, it should either be (a) a fundamental type [which are easy to spot] (b) a class or (c) an enumeration. Is it really that difficult for someone reading the code to identify what's a class and what isn't? (And if we follow this thought, all enumerations should begin with "E")
Some recent books I have read have stated that "C" and "T" were really used to avoid naming conflicts with other class names -- both these syntaxes were adopted before namespaces were created. But if everyone used "C" (again w/o namespaces), then name conflicts were just as likely to occur.
Personally, I don't think a "C" makes anything look more clear. But again, that's just my feelings on the subject.
Personally, I care less with what is to be prepended.
Well... actually I go by convenience..
I have worked in projects where a we used a specific Abbr prepended to all classes in the system to denote something which was written as a part of the implementation of the project... So, when one looks at the class name it is easier to know where to look for.
Actually, I like it when things related to a particular system, if I may say so, be easily identifiable..
I agree, but that indicates that you don't always prepend with the same letter. I often do similar things using short abbreviations so that I know where to look for things. But I have seen some applications where every class has a "C" in front. I am used to it and it doesn't disrupt my thought or anything. I am just curious why the practice is so prevalent. That's why I posted so many options in the poll.Quote:
Originally Posted by kirants
I dunno either. When I initially started off working with MFC, I did have that habit ( of prepending a "C" ), but I have gotten rid of that now..
I try to be more meaningful now..
It doesn't make sense to use "C" as such.. Class names aren't as stringent as using __ or _ in front of variables/functions.
Well, well... I've never claimed it's absolute and final truth.Quote:
Originally Posted by KevinHall
I'd thought about it. Few times. :) And became to conclusion that when you use (or not) any prepending symbols it could be just a sort of habit in most cases.Quote:
If you think about it, if you're declaring a variable, it should either be (a) a fundamental type [which are easy to spot] (b) a class or (c) an enumeration. Is it really that difficult for someone reading the code to identify what's a class and what isn't? (And if we follow this thought, all enumerations should begin with "E")
When it's not a habit it could be caused by some kind of agreement - verbal or documented (obeying to company programming standard) - and in this case you'll never ask "WHY" because you already know the reason.
Well, it looks quite believable.Quote:
Some recent books I have read have stated that "C" and "T" were really used to avoid naming conflicts with other class names -- both these syntaxes were adopted before namespaces were created.
Most people adopt habits of others quite easily when they have no reason to oppose them. :)Quote:
But if everyone used "C" (again w/o namespaces), then name conflicts were just as likely to occur.
Really, not so many people face to a name conflict. But if they were they taught to use namespaces very quickly.
About "everyone"... I admit that C letter's used very often in win programming - suppose, 'cause MS bless such practice just as they bless hungarian notation and many other things. Finally, all that tiny habits form a sort of environment, atmosphere, aura... Some creatures breathe freely there, but some not.
Programming is just a kind of social life where common sense, rules, habits, public and private opinions coexist. Move to other country (Linux) and you'll find yourself in rather different world. :)
Yeah, it's just your feeling. It's not right or wrong. It just is.Quote:
Personally, I don't think a "C" makes anything look more clear. But again, that's just my feelings on the subject.
A "C" because it denotes "class", because Microsoft does it, for my own reasons, and because everyone else (should) do it.
I agree with Hokutata and I think the poll should have used check buttons instead of radio buttons.
And by the way, the word prepend is not actually a word. It doesn't exist in any english dictionary (that I have :D ).
Well...just because Microsoft does it, or you do it will not make me convinced that I have to do it as well... :eek:Quote:
Originally Posted by Hokutata
Prepend definition from dictionary.com
Please expand on this. I'm really curious why you hold this belief.Quote:
Originally Posted by Hokutata
Well Andreas, paying more attention, we can observe that Hokutata found more reasons to use "C" than just because Microsoft does it.Quote:
Originally Posted by Andreas Masur
Anyhow even the OP (KevinHall) put more items pro "C" in this poll (the score is 5-4). So, better is to do it ;)
Not on my watch. :DQuote:
Originally Posted by ovidiucucu
Well...no...I did it for sometime as well....getting forced by my company...however, I drift away from the whole hungarian notation (which is where this one was introduced) since these kind of notations do not make much sense in an object-oriented language anyway...Quote:
Originally Posted by ovidiucucu
The first time and last time I used the CSomeClass was because the company had a heavy influence from MS when porting to C++/NT. There was no reason for it then and no reason for it now.
But whatever floats your boat :)
/Why are we discussing this again?
To test a theory of mine: That people prepend their classes with "C" because they have somehow been brought up to believe that there is good reason to -- not because they actually have a good reason to. :) (OK, your company may force you to, but IMNSHO I don't believe that company has good reason.)Quote:
Originally Posted by Mick
Well...most-likely the compelling reason for most of them is the fact that Microsoft does it for their MFC classes... :cool:Quote:
Originally Posted by KevinHall
That's what I believe too. It's interesting though that nobody has stated that. Perhaps people don't like being associated with MS and gravitate (perhaps subconsciously) to more "logical" reasoning for their practices.... Of course this is a pretty small sample pool.Quote:
Originally Posted by Andreas Masur
I learned C++ by jumping into MFC, and being the forgetful type, I've gotten into the habit of prepending my classes with 'C'; structs with 'S' and enumerations with 'E'. That way I know just by looking at the name if it's a struct or a class. Then, I hit the F12 key to look it up anyhow!! :)
I don't really hold an attachment to these prefixes, however old habits are hard to break...
:cool:
Viggy
Actually worked for one company [about 8 years ago] that required classes to be prepended with "A" or "An". The rational... "Instance is AClassName";
:eek: :lol:Quote:
Originally Posted by TheCPUWizard
Well... for some reasons, VC7 doesn't automatically prepend the 'C' prefix anymore.Quote:
Originally Posted by Andreas Masur
Well...no further comments... :cool:Quote:
Originally Posted by TheCPUWizard
Well...they might have figured out that any notation dedicated to the datatype is useless for object-oriented languages... :cool:Quote:
Originally Posted by Kheun
It probably also has to do with the smarter IDE. On VC7, when we position the mouse cursor over a declaratoin, it pops up tool tib indicating if it is a class, enum, etc.
As I already said, and also did Hokutata, I use C to prepend (this is not an english word until it gets into the Oxford Dictionary :D) my classes because it denotes class, it is used by Microsoft, because it has something to do with the Hungarian notation, because many others do it and finally because I think it is a good convention.Quote:
Originally Posted by KevinHall
Deep down in my subconscious mind might be a single reason, but I'll let Freud followers to find it. :D
Another question you should ask is why did Microsoft used "C" to prefix classes in MFC from the first place?
Because even some MS employees are Hungarian born ;) the common language used there is English. Imagine a parallel world with MS a German company: for sure they use K as prefix for Klasse names. :DQuote:
Originally Posted by cilu
You may prepend it with "C", with other character, or do not prefix it at all.
In any case the compiler will be not upset for that. :)
It's important that your code to be easy to read by the others.
I.e. to be not necessary to add tons of comments, explain what's this, write tens-pages documents ;), hit often F12, and blah-blah...
So, if the code you are writing it's not only for your own joy, it's good to respect some naming conventions. And this it's easy, just you must want it ;)
If the convention mentioned above is already widely used, it has no sense to invent the wheel... Even you like Microsoft or not :D
Quote:
Originally Posted by cilu
get Babylon :D :D
This may be an excellent guide for every programmer annoyed by the rules and recommendations.
How To Write Unmaintainable Code
:)
Thanks for the laugh and I don't mean the link, I mean the argument you just tried to pass.Quote:
Originally Posted by ovidiucucu
Well, generally everything is A or An.Quote:
Originally Posted by TheCPUWizard
My boss (as at least I know) does not read this forum.
So I'm lucky... he'll never see such great ideas... :D
Maybe I've missed it in the previous threads. Or maybe I'm just thick skulled ;) . But I don't recall anyone saying why they believe it is a good convention other than MS does it or other people do it. What makes it a good convention?Quote:
Originally Posted by cilu
Sure, but I could also ask why MSVS 7.x Wizards no longer prepend class names with "C".Quote:
Originally Posted by cilu
See? So much questions to be ask... :DQuote:
Originally Posted by KevinHall
Question is, how do you prefix your classes? Or you don't?
I don't prefix my classes with anything. I don't really see the need to.
Now when I'm using C for my company (yes we still have some legacy C code), then I prefix our structures with our company name's initials to avoid naming conflicts (as we use pretty common names for the applications our APIs are used in).
But cliu, I'm still waiting for you to explain to me why prepending class names with "C" is a good convention. :)
Another fact: Not only VC7 Wizard no longer prepend class names with "C", it's C# library also doesn't use "C" prefix to named it's classes. This would bring another question: If it is really good then why does MS abandon that for C# library? Probably, MS developers have figured out a reason why they don't need "C" prefix to pepper their code?
In case, somebody may ask why MFC still uses "C" prefix, it is simply because MFC has been widely used. Should MS decide to change all naming convention for MFC, it can create many tormoils. Not only all affected users have to replace all class names, they might even have to rerun tests to ensure that their programs work. This situation is very much similar to standard languages like C/C++, some decreprated functions just never die because there are always some code that use it.
Much Ado About Nothing
Back to work, philosophers!
:D
I really don't know how much you want me to elaborate on that. If you're expecting a book or something I will disappoint you. :) I kinda like the Hungarian convention, with C prefixing classes, S prefixing structures (I don't really use it, don't ask me why :D), m_ class member variables, or g_ global variables.Quote:
Originally Posted by KevinHall
Let me ask you something. You don't prefix classes. But do you prefix variables, with m_, g_ or something else? And if so, why do you do it?
I don't prefix variables with marks denoting "member" or "property" or anything like that. A member is easy to see because of the preceeding "." or "->".Quote:
Originally Posted by cilu
As for hungarian notation, it has value -- especially when pointers are used frequently, when you need to mark a boolean value in a language that doesn't have true booleans, and/or when you don't have an IDE that can help you figure out what type a variable is. The problem with hungarian notation is that with C++ there are now a lot more standard types (different from fundamental types):
vectors, lists, maps, complex (all of which so far are templates) and many others. So comming up with short abbreviations for all these types would be challenging:
vecIntName vector of integers (not too bad)
lstBoolName list of bools (not too bad either)
mapCpxIntStrName map of complex<int>s to strings (utterly confusing)
I believe that hungarian notation is better suited toward C, but for C++ insisting on it can make things more confusing than clear. I used hungarian notation for a while when using C (and some C++ a long time ago), but have have not used it for quite some time.
So in summary, no I don't prefix my variables with anything. I usually just name them clearly for their purpose (which often makes clear what the variable type is -- for example NameVector would be a vector of strings) and provide good documentation for others.
I use the C 'cause I know the wizard will make it will disapear and to use my CHARGE class I'll have to #include the HARGE.h header.
In case you don't know you have full control over the file names, both for .h and .cpp. The wizzard eliminates by default the "C" prefix from the class name and uses the rest to name the files. Just press the "Change" button and change them by your wish.Quote:
Originally Posted by RickCrone
Prepend "Charge" with a "C" ----> CCharge, then the good wizard will generate Charge.h/cpp and you'll have nomore headaches. :)Quote:
Originally Posted by RickCrone
I should have added an option on the poll: "C" because VC6's MFC class wizard adds it for me. I wonder how many people really just use "C" for that reason.
Well...I have added it... :cool:Quote:
Originally Posted by KevinHall
Did I ever preppended my class names with something???
Well, in fact I did preppend with "lpp" when I started with C years ago, when no namespaces were available. For normal variables or other kinds of things (enumerations, structs or whatever) I was more confortable preppending something like the enumeration name for variables of an enumerated type, for example:
and so on. The same for 'non-bool-type' bools: bool_try, bool_exit, etc.Code:enum colors {
red, blue, green;
};
enum colors colors_window, colors_door;
I think now with C++ as an OOL and namespaced availabe almost everywhere, preppending names with something related to tyhe type is unnecesary. I'd rather preppend something indicating the usage, ala "CarMap", for a map that maps car types to, whatever, license numbers.
Just to chime back in....
I do not currently repent names with anything to indicate their type [with the exception of certain ui elements], but I do use a combination of capitalization and prefix to indicate name scope:
local variables start with lower case.
Methods [verbs], Properties[adjectives] and Classes[nouns] start with UpperCase.
member variables are prepended with an m_
global (rare) are prepended with a g_
statics (variables) are prependes with an s_
I use a coding-convention somewhat similar to the one TheCPUWizard uses.
Globals get a g_
Member-variables a m_
Statics a s_
Function parameters get a p_
For class-names (and local variable-names) I follow the convention used in the standard-library; all small letters, with words separated by an underscore. Nothing prepended or prefixed or whatever the word is... The reason for adopting that style is that I do a lot of library-development, and by using a style similar to the standard-library, users tend to feel more comfortable using them. (A *nix coder being forced to use a library written using Hungarian-notation would probably feel a bit alienated!)
I have been using Hungarian notation (A long time ago), but I found it to be too much of a hassle as opposed to what I would get back (in terms of readabillity) for the effort.
Well I do what ever strikes my fancy when I happen to write a piece of code.
One day I am all for hangarian and use it like crazy, heck I even sprinkle a little
hungarian on the the hungarian and toss some postfix on there for good measure.
g_d_m_Wow_l_v_
Othes days I can not stand lower case but am still in the hungarian mood
G_D_M_WOW_L_V
Some days I am feeling lazy and so don't want to type
w
Or am lazy but still cry out in agony when forced to type lower case
W
You know....
p.s. Who out there can honestly say they have actually looked at a variable
and said, "by golly I would have thought that was a string, good thing I used hungarian notation" ?
Is C++ the first lanquage you have coded in?Quote:
Originally Posted by souldog
/We didn't have those fancy IDE's you fellars have these days...it was called print it out and take it home...