Skip to content

Latest commit

 

History

History
64 lines (47 loc) · 2.44 KB

File metadata and controls

64 lines (47 loc) · 2.44 KB

cppfw coding style

C++ naming conventions

  • Naming convention is defined by clang-tidy config file which can be found in https://github.com/cppfw/tool-configs repo.

  • factory functions must use word make (not create, etc.). E.g. make_object(param1, param2).

  • When variable name clashes with type name, then the variable name should have a _v suffix.

boolean types

variables

Boolean variables should be named as is_<something> or obviusly enough to understand from the variable name that it’s type is bool.

return values

When a function returns a bool, then such a function should be named as is_<something>() or obviously enough to understand from the function name that it returns bool.

function arguments

When a function have bool arguments, the function should be named in a way that it is obvious that it’s argument is a bool and the meaning of true or false passed values is clear. Likely, the function will have just one argument (the bool one`) and will be named like set_<something>(bool). For example: void set_visible(bool), void set_caching_enabled(bool).

When there is a need to have a bool-like argument, but the function name is not that obvious about the meaning of a passed in true/false value, then an enum with two descriptive items should be introduced and used as the argument. For example:

enum class button_action{
    press,
    release
};

virtual void on_mouse_button_event(vector2 position, button_action action);

instead of

virtual void on_mouse_button_event(vector2 position, bool is_pressed);

because at the place of the function call it looks like:

on_mouse_button_event(
    vector2{100, 200},
    button_action::press // meaning is obvious
);

vs

on_mouse_button_event(
    vector2{100, 200},
    true // what does this true mean? Need to look it up from a function documentation, not obvious from here.
);

no "managers"

Do not name any class/system a manager. Managing something is too wide term, it does not tell what exactly is being done with that "something" while it is being managed.

Come up with a better descriptive name which will clearly tell what the class/system does.

For example, instead of resource_manager, name it resource_loader or recource_provider.

C++ code formatting

Code formating is defind by clang-format config file which can be found in https://github.com/cppfw/tool-configs repo.