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 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 MY_MACRO snake_case is used for in-class event definition macros
function name snake_case my_function
struct/class name snake_case my_class
interface class name snake_case; i_ prefix i_my_interface an interface class does not have any member variables, containing only pure virtual functions and any associated helper functions
enum class name snake_case my_enum
enum name snake_case; _e suffix my_enum_e C-style enums
enumerator UpperCamelCase MyEnumerator
function parameter CamelCase; a prefix myVariable "a" for argument
local variable lowerCamelCase myVariable
member variable (class) CamelCase; i prefix iMyVariable "i" for class instance variable
member variable (struct) lowerCamelCase myVariable use struct for classes that don't have a class invariant
variable with static storage duration CamelCase; s prefix sMyVariable
variable with thread local storage duration CamelCase; t prefix tMyVariable
event object UpperCamelCase MyEvent
event (virtual) getter function snake_case my_event

Example class:

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