|
| 1 | += C++ Code Style |
| 2 | + |
| 3 | +This document briefly summarizes stylistic choices made in fuquery subprojects. |
| 4 | + |
| 5 | +== Layout and namespaces |
| 6 | +Currently there are three top-level namespaces used in fuqery projects: |
| 7 | + |
| 8 | +* `rsl` for the rsl project |
| 9 | +* `re` for the retest project |
| 10 | +* `erl` for **e**xperimental **r**eflective **l**ibraries |
| 11 | + |
| 12 | +Relative to the repository's root the primary include path must be `include/<namespace>` where `<namespace>` is the associated top-level namespace. Files in this folder are considered part of the public API, may contribute to the associated top-level namespace directly and shall not have a file extension. |
| 13 | + |
| 14 | +Implementation details shall be collected in a directory whose name starts with `_impl`. For top-level namespaces shared between projects, the project name must be included (ie `include/rsl/_impl_config` for rsl-config). Implementation detail headers shall have the file extension `.hpp` and may **not** contribute to the associated top-level namespace directly. |
| 15 | + |
| 16 | +== Macros |
| 17 | +=== Dollar macros |
| 18 | +[source,c++ diff] |
| 19 | +---- |
| 20 | +- RSL_INLINE(always) |
| 21 | ++ $inline(always) |
| 22 | +void foo() {} |
| 23 | +---- |
| 24 | + |
| 25 | +MSVC, GCC and Clang explicitly support `$` in identifiers. However, GCC notes that this might cause issues with some target assemblers. Since macros are gone at that point, the use of dollars in macro identifiers is unproblematic. |
| 26 | + |
| 27 | +This distinguishes macros clearly from other source constructs, therefore use of dollar macro identifiers is encouraged. |
| 28 | + |
| 29 | +== Identifiers |
| 30 | +=== Format |
| 31 | +Two different styles are used throughout the projects. For top-level namespaces standard library style should be used, meaning: |
| 32 | +[source,c++] |
| 33 | +---- |
| 34 | +// namespaces are always snake_case |
| 35 | +namespace rsl { |
| 36 | +
|
| 37 | +// snake_case for types in the rsl namespace |
| 38 | +struct some_type; |
| 39 | +
|
| 40 | +// snake_case for functions, variables etc |
| 41 | +void some_func(); |
| 42 | +constexpr inline bool some_var = true; |
| 43 | +} |
| 44 | +---- |
| 45 | + |
| 46 | +However, in implementation details we are free to use a slightly different style: |
| 47 | +[source,c++] |
| 48 | +---- |
| 49 | +// implementation detail namespaces begin with _impl_ |
| 50 | +namespace rsl::_impl_foo { |
| 51 | +
|
| 52 | +// PascalCase for types |
| 53 | +struct SomeType; |
| 54 | +
|
| 55 | +// snake_case for functions, variables etc |
| 56 | +void some_func(); |
| 57 | +constexpr inline bool some_var = true; |
| 58 | +} |
| 59 | +---- |
| 60 | + |
| 61 | +=== Uglifying members |
| 62 | +To ensure specific types are structural types, we sometimes cannot have non-public data members. Whenever this is the case, uglify the identifiers by prepending `_impl_`. |
| 63 | + |
| 64 | +[source,c++ diff] |
| 65 | +---- |
| 66 | +struct something_structural { |
| 67 | +- int secret; |
| 68 | ++ int _impl_secret; |
| 69 | +}; |
| 70 | +---- |
0 commit comments