- safe C practices should generally be preferred over modern C++
- perform static and runtime assertions where possible, i.e: array bounds, pointers, sizes
- everything_is_in_snake_case_and_verbose
long structure_bsp_index;
typedef is deprecated, prefer using statements with names that have no prefix (try not to use these)
using real = float; // correct
typedef float real; // deprecated
- mutable global variable names start with
g_
extern s_object_type_definition g_object_type_definitions[];
enum and enum class names start with e_
enum e_cache_file_shared_type;
struct names start with s_
- class names start with
c_
class c_cache_file_reader;
const global variable names and enum capacity members start with k_
enum e_field_type
{
_field_tag,
// ...
_field_terminator,
k_number_of_field_types
};
struct and class fields are each declared on their own lines
struct s_real_point3d
{
real x;
real y;
real z;
};
- datatype classes should be explicitly declared
final
class c_datum_handle final
{
private:
long m_value;
public:
// ...
};
- pure-virtual classes should explicitly declare
novtable
class __declspec(novtable) c_cache_file_metadata_and_fixup_loader
{
public:
virtual bool load_metadata_and_fixup(...) = 0;
};
- function parameters are each declared on their own line
bool tag_interop_fixup_manual_for_cache(
s_tag_interop *interop_object,
long cache_file_type_index,
c_aligned_allocator *allocator,
c_cache_file_fixup_verifier *verifier);
- curly braces always go on their own line
// wrong:
void do_something_wrong() {
// oh no!
}
// correct:
void do_something_right()
{
// oh yea!
}
- header files (.h) are divided into the following sections:
/* ---------- constants */
/* ---------- macros */
/* ---------- types */
/* ---------- classes */
/* ---------- globals */
/* ---------- prototypes */
- source files (.cpp) are divided into the following sections:
/* ---------- private constants */
/* ---------- private macros */
/* ---------- private types */
/* ---------- private classes */
/* ---------- globals */
/* ---------- private prototypes */
/* ---------- public code */
/* ---------- private code */