dev:codingconventions
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
dev:codingconventions [2015/08/21 21:00] – [Use existing infrastructure] oschuett | dev:codingconventions [2020/08/21 10:15] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== Coding Conventions ====== | ====== Coding Conventions ====== | ||
+ | |||
===== Stick to the standard ===== | ===== Stick to the standard ===== | ||
- | | + | |
- | * Avoid using new OOP aspects, because compilers do not yet support them well enough. | + | |
- | * OpenMP code should follow | + | * OpenMP code should follow version 3.X of the standard |
- | * MPI should should follow | + | * MPI should should follow version |
- | * Extended functionality should match [[wp> | + | * Extended functionality should match [[wp> |
===== Write explicit code ===== | ===== Write explicit code ===== | ||
Line 15: | Line 16: | ||
* INTEGER i=4.9999, i.e. i=INT(4.9999) implies i==4. Use NINT(4.9999) as appropriate. | * INTEGER i=4.9999, i.e. i=INT(4.9999) implies i==4. Use NINT(4.9999) as appropriate. | ||
* natom*natom, | * natom*natom, | ||
+ | * always use REAL() with KIND parameter, i.e. r = REAL(i, KIND=dp). | ||
+ | * avoid FLOAT() in favour of REAL(, KIND=dp). | ||
* the global number of grid points (pw_grid_type%ngpts, | * the global number of grid points (pw_grid_type%ngpts, | ||
===== Don't use poorly designed language features ===== | ===== Don't use poorly designed language features ===== | ||
* Do not use the '' | * Do not use the '' | ||
- | * Do not use left-hand-side (lhs) reallocations of allocatables [-Wrealloc-lhs-all]. [[http://www.tddft.org/pipermail/octopus-devel/2012-February/005510.html | + | * Do not use left-hand-side (lhs) reallocations of allocatables [-Wrealloc-lhs]. [[https://github.com/cp2k/cp2k/issues/726 | Why? ]] |
* Do not use '' | * Do not use '' | ||
* Do not use '' | * Do not use '' | ||
+ | * Do not query the '' | ||
+ | * Do not use '' | ||
===== Fight spaghetti code ===== | ===== Fight spaghetti code ===== | ||
Line 34: | Line 39: | ||
===== Use existing infrastructure ===== | ===== Use existing infrastructure ===== | ||
- | For many common | + | |
+ | Always prefer [[https:// | ||
+ | |||
+ | * '' | ||
+ | * '' | ||
+ | * '' | ||
+ | |||
+ | |||
+ | For many common | ||
* Use the routines from '' | * Use the routines from '' | ||
* Use the routines from the full-matrix '' | * Use the routines from the full-matrix '' | ||
* Use the routines from '' | * Use the routines from '' | ||
+ | * Use the routines from '' | ||
* Use the routines from '' | * Use the routines from '' | ||
- | * Don't use '' | + | * Don't use '' |
- | iw = cp_logger_get_default_unit_nr() | + | * Use [[error_handling|CP2K' |
- | IF(iw>0) WRITE (UNIT=iw, ,,,)</ | + | |
===== Remove dead code ===== | ===== Remove dead code ===== | ||
- | Every line of code has to be compiled and maintained. Hence, unused variables and code poses an unnecessary burden and should be removed. | + | * Every line of code has to be compiled and maintained. Hence, unused variables and code poses an unnecessary burden and should be removed |
+ | * Sometimes | ||
===== Format and document code ===== | ===== Format and document code ===== | ||
Line 51: | Line 66: | ||
* Each module and routine should be annotated with [[dev: | * Each module and routine should be annotated with [[dev: | ||
* Each preprocessor flag should start with two underscores and be documented in the '' | * Each preprocessor flag should start with two underscores and be documented in the '' | ||
- | * The code should be formatted with the prettify-tool by running '' | + | * The code should be formatted with the [[dev: |
===== Write tests ===== | ===== Write tests ===== | ||
* Every feature should be tested, with the goal of complete [[ http:// | * Every feature should be tested, with the goal of complete [[ http:// | ||
Line 63: | Line 77: | ||
* Please run '' | * Please run '' | ||
* See our [[ http:// | * See our [[ http:// | ||
- |
dev/codingconventions.1440190824.txt.gz · Last modified: 2020/08/21 10:14 (external edit)