This style guideline is roughly based on Google C++ style guide that can be found here; with some modifications that are enumerated in this document.
- We would like to keep the style in ORCA as close as possible to GPDB. This includes using tabs instead of spaces for indentation, all cap global constants etc.
- The ORCA code base previously was written completely in a version of Hungarian notation. To prevent large number of file renames, we also decided to keep the names of classes and files the same as much as possible.
That said, the specific style guidelines follow:
-
File names
- File names should match the main class in the file, whenever possible.
-
Type names
- Typenames start with a capital letter and have a capital letter for every
new word, with no underscores. For example,
MyExcitingClass
&MyExcitingEnum
- For typedefs of basic data structures (such as HashMaps), the typename
should include the type as a suffix. eg:
typedef CDynamicPtrArray <CBitSetLink, CleanupNULL> BitSetLinkArray;
- Typenames start with a capital letter and have a capital letter for every
new word, with no underscores. For example,
-
Variable names
- The names of variables (including function parameters) and data members
are all lowercase, with underscores between words.
For example,
variable_name
- Data members of classes and structs additionally have an additional prefix
of
m_
. For example,myobj->m_variable_name
- The names of variables (including function parameters) and data members
are all lowercase, with underscores between words.
For example,
-
Constant names & macros
- All macros definitions are written in all capital letters with underscore
between words. Use the same format for variables declared const in a
global scope.
For example,
#define MYMACRO
andconst int GLOBAL_CONSTANT = 4;
- However, variables declared as const as local variable in a function or
class should follow the same convention as a non-const variable would in
that context.
For example,
const int CMyClass::m_my_const = 5;
- All macros definitions are written in all capital letters with underscore
between words. Use the same format for variables declared const in a
global scope.
For example,
-
Function names
- All functions should start with a capital letter and have a capital letter
for each new word.
For example:
CallFunction()
- Accessors and mutators may be prefixed with
Get
andSet
respectively. But, this is not necessary for some trivial functions, such asarray->Size()
vsarray->GetSize()
. - Ideally, theses functions should start with a verb describing the
action(s) the functions is going to perform, rather than a noun. For
example, prefer
ReadBook()
overBookReader()
. - Since the
Get
andSet
prefixes suggest the method is a simple accessor or mutator, avoid using those prefixes for complex methods and do a lot of computations, and prefer aCompute
orCalculate
prefix for them instead .
- All functions should start with a capital letter and have a capital letter
for each new word.
For example:
-
Namespace names
- Namespace names are all lower-case.
-
Class, enumeration & struct names
- Class names should start with the capital letter 'C' and have a capital
letter for each new word. For example,
class CMyClass
. - Struct names should start with the capital letter 'S' and have a capital
letter for each new word. For example,
struct SMyStruct
. - Enumeration names should start with the capital letter 'E' and have a
capital letter for each new word. For example,
enum EOperatorId
. Each enumeration name may contain a Hungarian notational prefix for legacy reasons. For example,enum EOperatorId { EopLogicalGet, ... }
- Class names should start with the capital letter 'C' and have a capital
letter for each new word. For example,