C++ servey type thingy

Started by
9 comments, last by GameDev.net 18 years, 8 months ago
I just wanted to know what kind of type names and class names and all of the fun stuff people here prefer. functions my_func myfunc myFunc MyFunc variables my_var myvar myVar MyVar nMyVar standard types MYTYPE mytype_t myType_t MyType_t MyType unions UMyUnion MyUnion myunion_u (typedef to myunion_t) myUnion_u (typedef to myUnion_t) MyUnion_u (typedef to MyUnion_t) enumerators EMyEnum MyEnum myenum_e (typedef to myenum_t) myEnum_e (typedef to myEnum_t) MyEnum_e (typedef to MyEnum_t) structs MYSTRUCT mystruct_s (typedef to mystruct_t) myStruct_s (typedef to myStruct_t) MyStruct_s (typedef to MyStruct_t) MyStruct SMyStruct struct member variables m_myvar myvar_ myvar classes CMyClass MyClass abstract base classes MyInterface CMyInterface IMyInterface class member variables m_myvar myvar_ myvar class static variables s_myvar myvar_ _myvar myvar global/external variables g_myvar _myvar myvar enum vals/flags MYDEFINE PREFIX_MY_DEFINE PREFIX_MYDEFINE common constants MYDEFINE mydefine macros MYDEFINE MY_DEFINE templates TMyTemp mytemp MyTemp namespaces mynamespace MyNamespace NMyNamespace plz let me know if i'm forgetting something. [Edited by - Yohomyth on August 17, 2005 9:27:14 PM]
------------------------------------------------------------"Many combilations elizagerth. I hope you see my particles." - Senor Cardgage
Advertisement
This is just my personal opinion (so please no idiotic response from anyone, its just a meaningless personal opinion):

All uppercase letters for type names are an abomination.
Hardcore Hungarian notation is also an abomination and almost completely pointless in modern IDEs.

I've come to relize that trying to use different name conventions than the one a language uses (or its standard library uses) looks ugly. For instance i use to use camel notation in C++ but it looks completely out of place when using C++ standard library components as they don't. So i changed all my code to a style very similar to (may aswell be the same as) the C++ standard library (as does boost library) uses and now code looks more cohesive, yada, yada.

[Edited by - snk_kid on August 17, 2005 7:07:23 PM]
Fundamental types:
int, short, etc... or int8_t, int16_t using the C99 stdint.h notation.

Typedefs:
typically foo_t or foo_type depending on the usage.

Class names:
TitleCase

Function names:
lowercase_with_underscores()

Variable names
this_is_a_variable;

Member variables:
with_a_trailining_underscore_

Globals:
Happens rarely enough - I don't know

Struct:
structs are classes
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
Types (Enums, classes, typedefs): LikeThis

Abstract base classes: ILikeThis

Functions and variables: like_this

Private member variables: like_this_

Preprocessor defines and enumeration values: LIKE_THIS

Classes, structs, enums, typedefs: FooBar
Enumerants: FOOBAR_BAZ
Functions: FooBar
Macros: FOO_BAR
Variables: fooBar
Member Variables: m_fooBar
Global Variables: Don't know, I haven't used them in a while
Interfaces (abstract base classes): ITitle
Classes: CTitle
Structs: STitle
Template arguments: TTitle
Functions: Title
Enums: ENUMABBRV_TITLE
Macros: TITLE
Variables: mTitle, gTitle, title and longerTitle (locals/parameters)

I personally see tagging the variable type to the name (nTitle, m_fTitle) to be redundant.

EDIT: Anyone shove external library includes into a namespace to avoid name clashes? ie. namespace Win32 { #include <windows.h> }
I forgot to include why I posted this thread. I'm working on a library called RosClsLib, which will mostly be used for reading files of all kinds of formats, but can be used for other things like windowing and consoles. EDIT: and I want people other than me to pick the coding format for this. EDIT again: And I have headers to include stuff from Kernel32.DLL and User32.DLL and stuff so you won't have to #include <windows.h> or really anything other than "rcl.h".

[Edited by - Yohomyth on August 17, 2005 9:13:03 PM]
------------------------------------------------------------"Many combilations elizagerth. I hope you see my particles." - Senor Cardgage
standard types
MyType

enumerators
MyEnum

structs
MyStruct

struct member variables
my_var

classes
MyClass

abstract base classes
MyInterface

class member variables
my_var

class static variables
my_var

functions
myFunc

variables
myVar

global/external variables
myvar

enum vals/flags/common constants
PREFIX_MY_DEFINE

macros

MY_DEFINE

templates
MyTemp

namespaces

mynamespace


here's what i prefer:

functions: MyFunc
variables: myVar
standard types: mytype_t
enumerators: myEnum_e (typedef to myEnum_t)
unions: myUnion_u (typedef to myUnion_t)
structs: myStruct_s (typedef to myStruct_t)
struct member variables: myVar
classes: CMyClass
abstract base classes: IMyInterface
class member variables: m_myVar
class static variables: s_myVar
global/external variables: g_myVar
enum vals/flags: PREFIX_MYDEFINE
common constants: MYDEFINE
macros: MY_DEFINE
templates: TMyTemp
namespaces: MyNamespace
------------------------------------------------------------"Many combilations elizagerth. I hope you see my particles." - Senor Cardgage
I prefer clarity. Your style doesn't really matter, since I've written and maintained everything.

Matt

This topic is closed to new replies.

Advertisement