Naming Convention

From neoGFX
Jump to navigation Jump to search

The neoGFX naming convention is based on the idea that to aid readability of C++ code it is better to encode scope rather than type in an identifier name prefix. The idea of encoding scope in identifier names was introduced by the smartphone operating system EPOC32 (later Symbian OS).

The following table lists the various C++ syntactical constructs with their associated convention:

neoGFX Naming Convention
Construct Convention Example Note
macro upper snake case FOO_BAR snake_case is used for in-class event definition macros
function name snake case foo_bar
struct/class name snake case foo_bar
interface class name snake case; i_ prefix i_foo_bar an interface class does not have any member variables, containing only pure virtual functions and any associated helper functions
enum class name snake case foo_bar
enum name snake case; _e suffix foo_bar_e C-style enums
enumerator upper camel case FooBar
function parameter camel case; a prefix aFooBar "a" for argument
local variable lower camel case fooBar
member variable (class) camel case; i prefix iFooBar "i" for class instance variable
member variable (struct) lower camel case fooBar use struct for classes that don't have a class invariant
variable with static storage duration camel case; s prefix sFooBar
variable with thread local storage duration camel case; t prefix tFooBar
event object upper camel case FooBar
event (virtual) getter function snake case foo_bar

Example class:

class foo
{
public:
   foo(int aValue) : iValue{ aValue }
   {
   }
public:
   int value() const
   {
       return iValue;
   }
   void something()
   {
       thread_local qux tQux;
       /* ... code ... */
   }
private:
   int iValue;
};