C++ notation and naming conventions
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
Standards are great! There''s so many to choose from!
It depend on the library. The STL favors lower_case and no warts.
It depend on the library. The STL favors lower_case and no warts.
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
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 */
/*=========================================*/
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!
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 )
YES, IS A MUST!!
(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!!
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
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?
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 ]
[ MSVC Fixes | STL | SDL | Game AI | Sockets | C++ Faq Lite | Boost | Asking Questions | Organising code files ]
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement