Naming convention
hannorein opened this issue · 1 comments
hannorein commented
The naming of variable and function names really needs to be made more consistent. It's all over the place right now.
- Given that most people probably use the Python API, we should follow PEP8. Specifically: function names and variables use lowercase, with words separated by underscores as necessary to improve readability.
- The C equivalents should mostly follow Python.
- Structures in c do not use typedef. They are always referred to
struct
, e.g.struct reb_simulation
. - Structure names in C start with the prefix
reb_
followed by small letters, words are separated with underscores, e.g.reb_hash_pointer_pair
. - Class names use the CapWords convention in python and ignore the
reb_
prefix.reb_simulation
<->Simulation
,reb_simulationarchive
<->Simulationarchive
,reb_hash_pointer_pair
<->HashPointerPair
- Only use verbs in a function name if the function changes the state.
- Simulationarchive is one word.
_simulationarchive_
in c andSimulationarchive
in python. - Variables describing memory allocation have names such as
N_allocated_collisions
. - Function names should start with the main object they operate on:
reb_simulation_move_to_com()
. - Structure names used in function names do not use CapWords, e.g.
reb_simulationarchive_take_snaphot()
- Function names should have a name such that switching between C and python becomes trivial:
reb_simulation_energy()
<->rebound.Simulation.energy()
. - Avoid "set" and "get" in function names. Instead of
reb_get_com()
usereb_simulation_com()
. - Memory management:
create
, allocates and initializes an object.free
frees the memory of an object (and all the objects it owns).init
does not allocated an object itself, but merely initializes it with default values. The verb follows the object, e.g.reb_simulation_create()
. - We won't provide deprecation warnings.
hannorein commented
Trying things out over on the namingconvention branch.