is there a standard naming convention in c++?
is there a standard naming convention in c++?
OS: Windows 7, XUbuntu 11.10, Arch Linux
IDE: CodeBlocks
Compiler: GCC
Yes, there are lots of them in fact!
This is the one I use:
- Variable names begin with a small letter and the first letter of each word in the name afterwards is capital (eg. int avgStudentMarks).
- Classes, Structs, Enums and Public Functions are the same as variables, except they begin with a capital letter.
- Private & Protected functions are the same as variable names.
- Class Member Variables ALWAYS start with m_ (eg. std::string m_FirstName).
- Macros & constants are all capitals.
Quick search: http://en.wikipedia.org/wiki/Identif...ing_convention
7. It is easier to write an incorrect program than understand a correct one.
40. There are two ways to write error-free programs; only the third one works.*
This is purly programmer preference, but when using a reference, I do this:
the small " r " helps to remember I am using a reference to another variable.Code:rMyName;
Also, with a variable you have declared as "const", use uppercase letters;
Leaving it uppercase ensures you know that you are dealing with a special variable, hence you know it must be constantly assigned a value.Code:const int MAX_ARRAY = 5;
Double Helix STL
Any reasonably large company or other organization will have it's own conventions.
I personally (when I do "hobby programming" use something similar to cpjust.
One example is Linux, which of course isn't C++, use all identifiers except macros as lower-case, using underscore to split parts of names up, e.g. avg_student_marks.
Another example is Microsoft, where they use a "hungarian notation", where a "pointer to zero terminated string" starts with psz then the name, e.g. pszFileName. All pointers start with p, a character starts with c, an integer with i, structures with "structname", e.g. a "struct rect" would be rectDrawRegion - and a pointer to a struct rect would be prectDrawRegion. This makes it easier to understand what the type of a variable is without looking up at the top of the function. Of course, opponents to this techniqeu would say that it adds "meaningless" info to the variables, since if you already know what type the variable is, then you don't need these "name decorations".
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
I like joels article about wrong understood vs. useful type of hungarian notation.
http://www.joelonsoftware.com/articles/Wrong.html
There are as many styles as there are programmers. (Yes, I've said that before.)
It's one of those things. Indentation. Whitespace. Naming conventions. Mention them and you often start a flame war . . .
This applies to preprocessor stuff as well. (cpjust mentioned this.) It's a convention inherited from C, and it's reasonably widespread.Also, with a variable you have declared as "const", use uppercase letters;
dwk
Seek and ye shall find. quaere et invenies.
"Simplicity does not precede complexity, but follows it." -- Alan Perlis
"Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
"The only real mistake is the one from which we learn nothing." -- John Powell
Other boards: DaniWeb, TPS
Unofficial Wiki FAQ: cpwiki.sf.net
My website: http://dwks.theprogrammingsite.com/
Projects: codeform, xuni, atlantis, nort, etc.
I use a special naming convention where if the next letter in the word as ascii code is equal to the start of the next letters ascii code I switch the letter to the third letter if exsisting and delete it and type something random.