-
Notifications
You must be signed in to change notification settings - Fork 218
/
style.txt
45 lines (32 loc) · 2.18 KB
/
style.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
Style Guide
===========
This is a short source code style guide for REBOUND. It is not enforced in any way and only intended to be a suggestion.
Functions (c)
-------------
* All non-static functions have the prefix reb_
* All lower case
* Multiple words are connected with underscores
* "Sentences" should follow "noun_verb" rule, where "noun" is the object that gets operated on. For example: reb_simulation_create() and reb_simulation_free()
* All functions belonging to a specific module have a common prefix. For example: reb_integrator_whfast_kepler_step(). This might get long, but note that this is only really required for functions intended for general use. Internal functions can be static and do not need to include the prefix.
Variables (c)
-------------
* The function naming convention rules apply.
* The only public variables are in structs. Therefore, they do not have the reb_ prefix.
* As an exception to the lower case rule: the number of particle N is capitalized.
* Variables beginning with an underscore are not intended for general use.
Objects (python)
----------------
* First letter is capitalized, all other letters are lower case
* Same name as in corresponding c struct except reb_ prefix. For example struct reb_particle is Particle.
* Instance methods in python drop the reb_ prefix and the noun from the corresponding c function. For example reb_simulation_move_to_com() becomes Simulation.move_to_com().
Specific function names (c)
---------------------------
* "create" describes a method which both allocates memory for the struct and then initializes the object. For example: reb_simulation_create()
* "reset" describes a method which resets the struct to (more or less) its initial values such that it can be used as if a new object was created. For example: reb_integrator_ias15_reset().
Header files (c)
----------------
* All struct and function definitions that a user might need to access are in rebound.h.
* Structs and function definitions that are specific to one module and are only used internally within the rebound library are in the module header files. For example: integrator_whfast.h.
Indentation
-----------
* Four spaces are used both in c and python for indentation.