|
| 1 | + |
| 2 | +The following are coding style guidelines for this project. |
| 3 | + |
| 4 | +Code is expected to be ANSI C compatible (C89). Use `/* ... */` comments, not |
| 5 | +`// ...` comments. |
| 6 | + |
| 7 | +The style is a variant on the K&R style. |
| 8 | + |
| 9 | +To automatically format all source code, install |
| 10 | +[clang-format](https://clang.llvm.org/docs/ClangFormat.html) and |
| 11 | +run `make format`. |
| 12 | + |
| 13 | +## Blocks |
| 14 | + |
| 15 | +Tabs are used for indentation, spaces for alignment, eg. |
| 16 | +```c |
| 17 | +for (...) { |
| 18 | +------>|function_call(..., ..., |
| 19 | +------>| .....); |
| 20 | +} |
| 21 | +``` |
| 22 | +Braces belong on the end of lines, eg. |
| 23 | +```c |
| 24 | +while (...) { |
| 25 | + if (...) { |
| 26 | + ... |
| 27 | + } else { |
| 28 | + ... |
| 29 | + } |
| 30 | +} |
| 31 | +``` |
| 32 | +The one exception is functions, where the brace goes on the next line: |
| 33 | +```c |
| 34 | +void foo(...) |
| 35 | +{ |
| 36 | + ... |
| 37 | +} |
| 38 | +``` |
| 39 | +
|
| 40 | +## Naming |
| 41 | +
|
| 42 | +Types are named with [camel case](https://en.wikipedia.org/wiki/Camel_case), |
| 43 | +eg. `HashTable`. |
| 44 | +All others (functions, variables, struct fields, etc.) are named with [snake |
| 45 | +case](https://en.wikipedia.org/wiki/Snake_case), eg. `hash_table_new`. |
| 46 | +
|
| 47 | +## Testing |
| 48 | +
|
| 49 | +No code will be accepted without unit tests. See the [test](test/) directory |
| 50 | +for what these should look like. Run `make check` to invoke the unit tests. |
| 51 | +
|
| 52 | +Tests should [cover](https://en.wikipedia.org/wiki/Code_coverage) at least |
| 53 | +95% of lines. Configure the project using `./configure --enable-coverage` and |
| 54 | +then run `make check`. |
| 55 | +
|
| 56 | +## Documentation |
| 57 | +
|
| 58 | +All public interfaces must be documented using |
| 59 | +[Doxygen](https://www.doxygen.nl/). For example: |
| 60 | +```c |
| 61 | +/** |
| 62 | + * Retrieve the number of entries in a hash table. |
| 63 | + * |
| 64 | + * @param hash_table The hash table. |
| 65 | + * @return The number of entries in the hash table. |
| 66 | + */ |
| 67 | +unsigned int hash_table_num_entries(HashTable *hash_table); |
| 68 | +``` |
0 commit comments