-
-
Notifications
You must be signed in to change notification settings - Fork 440
Tips on writing igraph code
Some tips on writing igraph code. In general, look at how things are done, and try to do them similarly. (Unless you think they are not done well, in which case please tell us.)
We use four spaces for indentation, Unix line endings, and UTF-8 encoding (which is relevant for documentation comments). igraph comes with an .editorconfig file, which defines these settings and is supported by many editors.
We aim to maintain a relatively consistent coding style within igraph. When contributing new code, please mimic the formatting style of the exiting code.
Try to use C, unless you are updating already existing C++ code, or you have other good reason for C++ (but then maybe ask us first).
We make conservative use of C99 features with the restriction that they must be supported by Visual Studio 2015 (compiler version 19.0). In cases when the use of C++ is necessary C++11 is allowed.
Please try to use igraph's data types for vectors, matrices, stacks, etc. If they lack some functionality you need, please tell us. Use igraph's native atomic types igraph_integer_t, igraph_real_t and igraph_bool_t instead of int, double or bool.
Please use igraph's memory allocation functions. Please also use the FINALLY stack: IGRAPH_FINALLY, IGRAPH_FINALLY_CLEAN, etc. See examples in the C code. For more information, see the Error reporting guidelines.
Please look at how random numbers are generated in any function in src/games.c. Do the same, i.e. use igraph's own RNG calls. Do not use the rand() function from the C standard library or any other random number generators.
Please document your new functions. The C documentation is included in the C source code. For more information, see the Documentation guidelines.
Unless you change something trivial, please consider adding test cases. This is important! See the tests/unit directory for examples of existing tests, as well as the How to write unit tests? wiki page.