|
nkr
A C++20 library with a custom meta-programming language.
|
(W.I.P)
We need to hook up these styles to the test suites to keep them updated as some of these are outdated.
Snake case is used for all names. Names are intended to follow natural grammars such that they are more easily discerned when trying to understand any particular piece of code. Thus short names, especially single character names, are usually unacceptable (with some exceptions). Descriptive names are the key to understanding code, however short postfix notation is sometimes employed to indicate differences between types of objects but especially to avoid name collisions.
Namespaces: lower_case. Short names are encouraged but not required. On occasion a namespace may contain a label with a postfix such as a type name:
Classes (Types): lower_case, *_t postfix*. These should usually be named after nouns:
Unions: lower_case, *_u postfix*. These should usually be named after nouns indicating the commonality between its types:
Template Parameters: lower_case, *_p postfix*. These are effectively meta variables and thus do not have the type postfix:
Aliased Types: lower_case, *_t postfix*. The same as regular types. Notice how the _p postfix for type parameters makes aliasing the same name easy:
Traits (Concepts Refining Template Parameters): lower_case, *_tr postfix*. These are effectively meta types and thus have a postfix, albeit distinct from regular types. These should usually be named after adjectives:
Functions: Upper_Case. Functions should usually be named after verbs. There may be rare occasions where other type labels are included in a function name, and they too should be written in lower case, with the postfix remaining lower case:
Function Acronyms and Idioms: CAPITAL_CASE. When a function name has an acronym, it should be in all caps. Special idiomatic expressions may also be in all caps:
Methods: Upper_Case. Methods should usually be named after verbs except if they are a getter or a setter, in whice case they can simply be the capitalized name of the data member:
Pointer to Function or Method: Upper_Case. These are exactly the same as their Function and Method counter-parts:
Interfaces: lower_case, *_i postfix*. Whether C++20 concepts defined by requires-expressions, abstract virtual classes, structs of function pointers, or anything else that genuinely qualifies as an interface:
Variables: lower_case:
Constants: lower_case:
Constexprs: CAPITAL_CASE:
Enums: CAPITAL_CASE.
Enum Types: lower_case, *_e postfix*.
Macros: CAPITAL_CASE, nkr_ prefix. In order to not pollute the namespace, every single macro without exception shall be prefixed with the name of the library:
Macro Parameters: CAPITAL_CASE, *_p postfix*:
Collisions: On occasion there will be name collisions with lower case labels and keywords. In those instances, it is recommended to postfix a $ before the label name:
Namespaces should always have a space after their opening brace and before their closing brace, and at least a third line, either of code or space:
Nested namespaces must be on one line, and so namespaces should end up only having one indentation. When working with multiple namespaces, each namespace should have its own block: