C++ notation and naming conventions

Started by
48 comments, last by Cybertron 21 years, 8 months ago
I am working on a new graphics interface right now using OOP, and was wondering what are the standard naming conventions for classes, variables, functions and enums I already use hungarian notation for variable names (except for ''m_'' or ''g_'') but classes are all over the place and functions are usually just describe what they do In need your input on a logical way to orginize all these data types and structures
Advertisement
Standards are great! There''s so many to choose from!

It depend on the library. The STL favors lower_case and no warts.
- The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara
quote:Original post by Cybertron
I am working on a new graphics interface right now using OOP,
<snip>
I already use hungarian notation for variable names

Some people are going to tell you that HN is redundant in an OO world.



"I would defend the liberty of concenting adult creationists to practice whatever intellectual perversions they like in the privacy of their own homes; but it is also necessary to protect the young and innocent."
Arthur C Clarke
--AnkhSVN - A Visual Studio .NET Addin for the Subversion version control system.[Project site] [IRC channel] [Blog]
quote:Original post by Magmai Kai Holmlor
Standards are great! There''s so many to choose from!


Haha! Too true, too true.

/*=========================================*/
/* Chem0sh */
/* Lead Software Engineer & Tech Support */
/* http://www.eFaces.biz */
/*=========================================*/
/*=========================================// Chem0sh// Lead Software Engineer & Tech Support// http://www.eFaces.biz=========================================*/
The only "notation" I use are to indicate scopes and
to distinguish pointers from other types.

g_ : global variable (ewww!)
m_ : member variable (very nice)
s_ : static variable (...)
p : pointer variable (MUST!)

That''s all! I need to distinguish pointers from the others
because pointers use -> rather than . to access members.
References are fine in that regard.


Kami no Itte ga ore ni zettai naru!
神はサイコロを振らない!
Here''s my notation:
(local) variables:-- item, itemIndex, itemStr (not strItem, yuk!)
member variables:-- item_, itemIndex_, itemStr_
global variable:-- theItem, theItemIndex, theItemStr
pointer:-- pItem, pItemIndex, pItemStr
pointer global:-- pTheItem, pTheItemIndex, pTheItemStr

(member) functions:-- EatItem(), Eat()
#define/const int:-- MAX_ITEM, MAX_SIZE, LOG()
classes/structs:-- Star, Rectangle, Object, Alien, SuperAlien
template <class X>:-- where X = T, U ,V ,W... or A (for allocator )
quote:Quote from tangentz
p : pointer variable (MUST!)

YES, IS A MUST!!
"after many years of singularity, i'm still searching on the event horizon"
local - var
global- ::var
member- this->var
static- class_name::var
- The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara
I put caps on things that there are one of, and go lower case with underscores for members.

Class
GlobalVariableOrFunction
StaticVariableOrFunction

member_variable_or_function
local_variable_in_a_function

so if you see C::D you know it is static whereas C::d is just a plain member. Likewise if you see V you know it is a global variable or function and if you see v it is a local variable of function
Thanks for the input

It looks like naming scope of the variable is a good idea. local variables can be left alone but classes can have all their variables prefixed with m_.

What should I call classes? I either start it with C or ends in "Class". Interfaces usually start with I_ (like I_GraphicsInterface). What could I call the implementation of that interface?
What use is a prefix to denote scope? Everything should have as small a scope as possible anyway.

[ MSVC Fixes | STL | SDL | Game AI | Sockets | C++ Faq Lite | Boost | Asking Questions | Organising code files ]

This topic is closed to new replies.

Advertisement