Naming Convention: Difference between revisions

From neoGFX
Jump to navigation Jump to search
No edit summary
No edit summary
 
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
The ''neoGFX'' naming convention is based on the idea that to aid readability 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 ''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:
The following table lists the various C++ syntactical constructs with their associated convention:
Line 18: Line 18:
| enum class name || snake_case || <code>my_enum</code>
| enum class name || snake_case || <code>my_enum</code>
|-
|-
| enum name || snake_case; <code>_e</code> suffix || <code>my_enum_e</code>
| enum name || snake_case; <code>_e</code> suffix || <code>my_enum_e</code> || C-style enums
|-
|-
| enumerator || UpperCamelCase || <code>MyEnumerator</code>
| enumerator || UpperCamelCase || <code>MyEnumerator</code>
Line 36: Line 36:
| event object || UpperCamelCase || <code>MyEvent</code>
| event object || UpperCamelCase || <code>MyEvent</code>
|-
|-
| event (virtual) function || snake_case || <code>my_event</code>
| event (virtual) getter function || snake_case || <code>my_event</code>
|}
|}



Latest revision as of 15:06, 5 May 2024

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
{
public:
   foo(int aValue) : iValue{ aValue }
   {
   }
public:
   int value() const
   {
       return iValue;
   }
   void something()
   {
       thread_local qux tQux;
       /* ... code ... */
   }
private:
   int iValue;
};