-
Notifications
You must be signed in to change notification settings - Fork 280
Code style
Coolthulhu edited this page Aug 25, 2021
·
3 revisions
List of conventions used in the project, plus just plain good practices. Not rules per se, most of the codebase doesn't meet those standards.
TODO: This should be in docs once finalized.
Good names:
- Are not abbreviated if it could make meaning less obvious -
count
, notcnt
- Are obvious from context -
direction::left
is clear,int rotate
requires reading the documentation - Obey same conventions as nearby names -
max_stored_kcal
andstored_kcal
, notmax_stored_calories
butstored_kcal
orcaloried_stored
snake_case
is preferred for consistency with most of the project's code.
- Don't add methods where a regular function in a namespace would work -
crafting::consume_tools(tool_list,Character &)
, notCharacter.consume_tools(tool_list)
- Don't add both getters and setters if all they do is read/write a field - those are just disguised fields
- Getters without (public) setters are OK
- Use
private
where possible,public
when not,protected
only when there's a clear reason for it
- Avoid pointers, instead use references,
cata::optional
or even a function overload where possible - Avoid using
std::pair
andstd::tuple
in headers, instead create a named struct - Avoid using
int
orstd::string
where anenum class
would work