View Full Version: Naming convention

C++ Learning Community > C++ in General > Naming convention


Title: Naming convention
Description: witch do you prefer ?


C-Man - January 6, 2005 09:36 PM (GMT)
lets say foobar is a class

Loki_Laughs - January 6, 2005 09:44 PM (GMT)


That depends on what the identifier is for.


Different conventions for:

MACROS

variables
member variables
static member variables
global variables
local variables

functions
global functions
static functions
methods
static methods

Types
Class
you get the idea.

Some of these overlap for me.


KTC - January 6, 2005 10:53 PM (GMT)
He said foobar was a class name :P (Yes, it varies for me as well)

TheHawgMaster - January 7, 2005 01:51 AM (GMT)
FooBar for classes... Camel notation for most else :)

Nintendofreak88 - January 7, 2005 02:11 AM (GMT)
I use FooBar for classes, class methods, and functions. Camel for everything else, like THM. :D

ih8censorship - January 7, 2005 04:22 AM (GMT)
moved to the general c++ forum since its not really a help topic. anyway for a class id use FOOBAR. im finding that i like types to be capitalized and then the object lowercase. i do all sorts of things with functionnames though :rolleyes:

Gmakermaniac!!! - January 8, 2005 03:20 AM (GMT)
FOOBAR for macros, FoObAr (or, like a sane person FooBar) for classes, functions, variables and members.

dorto - January 8, 2005 06:51 AM (GMT)
QUOTE (ih8censorship @ Jan 7 2005, 04:22 AM)
anyway for a class id use FOOBAR.

class id? you mean class name? though one can use any naming convention for naming classes, functions etc but using upper case for macros and constants is followed almost universally in c++ fraternity. so anything *other than* all-upper-case could be used for the class names etc. ofcourse, "underhanded names"(ones that begin with an underscore or that contain a double underscore) should NEVER be used.

vbgamer45 - January 8, 2005 07:40 PM (GMT)
I like CFooBar
Normally I like to have the first letter of the type lower case but in this case its better to keep the C upper case since thats what a lot of the classes use.
And then I like to captialize each word.

Gmakermaniac!!! - January 9, 2005 12:43 AM (GMT)
I dislike hungarian notation fore some reason. It kakes the names of everything more confusing when I can just place my mouse over the variable name to figure out it's type. It I were using notepad, I would consider using hungarian notation.

vbgamer45 - January 9, 2005 01:51 AM (GMT)
Makes things more confusing? How so? I find it better as soon as you look at a variable you instantly know the type and general function of it and don't have to go around finding what type it is.

dorto - January 9, 2005 04:02 AM (GMT)
Hungarian Notation is dead - even in microsoft circles.

Herb Sutter says: "it has mixed utility in type-unsafe languages(like C), it is possible but has no benifits (only drawbacks) in object-oriented languages(like smalltalk), and it is impossible in generic programming. Therefore, no C++ programmer should use Hungarian notation."

it has mixed utility in C like languages because: 1.(adv)it helps in identifying the type immediately by looking at the variable 2.(disadv)but when the type of a variable changes, it is not likely that you are going to hunt through all the code and change all occurrences of its name. For an example of this, look at the documentation for wParam in Microsoft Windows 32-bit: It changed from a 16-bit value (w stands for word) to a 32-bit value (which should have been dwParam)

in OO languages, variables are typeless - they contain an object, the type of which depends on the object itself, not the variable.

in generic code, ofcourse, hungarian notation is just impossible.

ih8censorship - January 9, 2005 05:00 AM (GMT)
QUOTE
anyway for a class id use FOOBAR.

class id? you mean class name? though one can use any naming convention for naming classes, functions etc but using upper case for macros and constants is followed almost universally in c++ fraternity.
actually it was class i would- contraction and forgot the ' so it would have been i'd :lol: but ya for the class name, and struct names i like to have uppercase, the reason is i like to retain in my short term memory what is an object, what is a class, what is a variable, what is a function. im finding i like to take advantage of c++'s case sensitive nature, so at a glance i can tell whats what (the case sensitive id's are very good for parameters of a function)

dr voodoo - January 9, 2005 09:26 AM (GMT)
QUOTE (ih8censorship @ Jan 9 2005, 05:00 AM)
QUOTE
anyway for a class id use FOOBAR.

class id? you mean class name? though one can use any naming convention for naming classes, functions etc but using upper case for macros and constants is followed almost universally in c++ fraternity.
actually it was class i would- contraction and forgot the ' so it would have been i'd :lol: but ya for the class name, and struct names i like to have uppercase, the reason is i like to retain in my short term memory what is an object, what is a class, what is a variable, what is a function. im finding i like to take advantage of c++'s case sensitive nature, so at a glance i can tell whats what (the case sensitive id's are very good for parameters of a function)

And I want to remeber what is a macro, what a class and what a variable:

MACROFOO
ClassFoo
var_foo
func_foo() or FuncFoo() or funcFoo()

It's no problem to seperate all 4 things using there names. A special convention for functions is useless because they are the only which are followed by a (.

C-Man - January 9, 2005 11:46 AM (GMT)
i dislike the hungarian notation cause it just looks plain ugly too me :wacko:
and i can't decide witch looks better to me
class_foo::funct_foo
or
ClassFoo::FunctFoo

dr voodoo - January 9, 2005 12:44 PM (GMT)
The hungarian notation looks pretty good in plain C. Just look at the winprog.net tutorials for a good example. (However this does not mean that I find the WinAPI good looking.) In C++ it's just ugly.

KTC - January 9, 2005 03:21 PM (GMT)
QUOTE (dr voodoo @ Jan 9 2005, 09:26 AM)
It's no problem to seperate all 4 things using there names. A special convention for functions is useless because they are the only which are followed by a (.

But but, what happens when we're using function pointers and have to use it name without the () ? :P

And to me, the API just look plain confusing with all its Hungarian notation. -_-

dr voodoo - January 9, 2005 04:41 PM (GMT)
QUOTE (KTC @ Jan 9 2005, 03:21 PM)
QUOTE (dr voodoo @ Jan 9 2005, 09:26 AM)
It's no problem to seperate all 4 things using there names. A special convention for functions is useless because they are the only which are followed by a (.

But but, what happens when we're using function pointers and have to use it name without the () ? :P

A function pointer is a fuctor, a copyable function, a function reference. No matter how you want to call it it keeps the workway of a function. You can always very quickly figure out of the context if it's a function or not.

Also function pointers are used much too rarly as if they'd need a special nameing convention.

QUOTE
And to me, the API just look plain confusing with all its Hungarian notation. -_-
The WinAPI is badly designed here no nameing convention of the world can change a thing. Which although doesn't mean that the hungarian notation itself is bad for C code.

tidy_trax - January 19, 2005 06:12 PM (GMT)
I use lower case for everything, so foobar.

aab - March 10, 2005 10:51 PM (GMT)
hmm Lets see...
I use different methods for different things..(as most probobly do)

foo_bar
CODE

#ifdef __cplusplus__
 0
#else
 (void*)(0)
#endif

foobar
_____ For private class members
Foo_Bar
_____ This is for basic. Always, if your coding basic this is for some insane reason depicted as the most important thing
eg: infuriatingly over written code they try to make us write in High school true basic programming:
CODE

! this sub calculateds the total amount raised
SUB Calculate_Total_Amount_Raised()

_____ Needless to say i laugh all throughout the course..
FooBar
_____ for public class members and functions
FOOBAR
_____ for class names
FOO_BAR
_____ for large macros
CFooBar
_____ Never
CFoo_Bar
_____ For one lib i made once. it was small and pathetic.
cfoobar
_____ Not at all. not enough distinction between the prefix'd 'type of data type' and data type.
cfoo_bar
_____ Never Never Never Never
cFooBar
_____ sometimes, for typedefs eg: typdef Bog,*pBog;
What about cFOOBAR? i use that.....
cFoo_Bar
_____ Never

C-Man - March 11, 2005 10:29 AM (GMT)
Very detailed ancwer :)

ramirez - April 6, 2005 09:08 AM (GMT)
FooBar.

I always name class names with capital letter (first letter), and I also capitalize every individual word (eg. class TextureSet).

Neken - August 14, 2005 10:49 PM (GMT)
FooBar, but sometimes, in a engine or a library, i put a single letter before the name of the class :

Engine nIrium
class nFooBar (that's a real exemple :P except for the foobar part :P)

Rmstn1580 - December 7, 2005 12:25 AM (GMT)
This post confused the hell out of me...




Hosted for free by InvisionFree