Skip to content
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.

Naming

Good names:

  • Are not abbreviated if it could make meaning less obvious - count, not cnt
  • Are obvious from context - direction::left is clear, int rotate requires reading the documentation
  • Obey same conventions as nearby names - max_stored_kcal and stored_kcal, not max_stored_calories but stored_kcal or caloried_stored

snake_case is preferred for consistency with most of the project's code.

Classes

  • Don't add methods where a regular function in a namespace would work - crafting::consume_tools(tool_list,Character &), not Character.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

Types

  • Avoid pointers, instead use references, cata::optional or even a function overload where possible
  • Avoid using std::pair and std::tuple in headers, instead create a named struct
  • Avoid using int or std::string where an enum class would work
Clone this wiki locally