Skip to content

Commit ae40ece

Browse files
committed
Add style guidelines file
1 parent bc20bea commit ae40ece

File tree

4 files changed

+71
-3
lines changed

4 files changed

+71
-3
lines changed

.github/CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ If you are planning to add a new module (data structure or algorithm), you may w
44

55
If you are planning to submit a pull request, please ensure that your change:
66
* Is written in the C programming language.
7-
* Conforms to the project's style guidelines.
7+
* Conforms to the project's [style guidelines](../STYLE.md).
88
* Does not duplicate existing code already present.
99
* Passes all unit test checks (existing code). Run `make check` to confirm.
1010
* Adds unit tests (new code) with at least 95% coverage. Build with `configure –enable-coverage` to confirm.

.github/pull_request_template.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ If you are planning to add a new module (data structure or algorithm), you may w
77
88
Before filing your pull request, please ensure that your change:
99
* Is written in the C programming language.
10-
* Conforms to the project's style guidelines.
10+
* Conforms to the project's style guidelines (see STYLE.md).
1111
* Does not duplicate existing code already present.
1212
* Passes all unit test checks (existing code). Run `make check` to confirm.
1313
* Adds unit tests (new code) with at least 95% coverage. Build with `configure –enable-coverage` to confirm.

Makefile.am

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
AUX_DIST_GEN = $(ac_aux_dir)
33

4-
EXTRA_DIST = $(AUX_DIST_GEN) libcalg-1.0.pc.in
4+
EXTRA_DIST = $(AUX_DIST_GEN) libcalg-1.0.pc.in STYLE.md
55
MAINTAINERCLEANFILES = $(AUX_DIST_GEN)
66

77
pkgconfigdir = $(libdir)/pkgconfig

STYLE.md

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
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

Comments
 (0)