dev:formattingconventions
Differences
This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
| dev:formattingconventions [2016/03/16 13:30] – created pseewald | dev:formattingconventions [2026/10/14 08:43] (current) – fstein | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | ====== Formatting Conventions ====== | + | ====== |
| - | Uniform formatting of CP2K source code will be enabled in the near future by a prettify script that is an almost complete auto-formatter for Fortran 90 source code. As a rule of thumb, developers should not worry about the format of their code and just let prettify do its magic by running '' | + | |
| - | * Sorting and alignment of variable declarations and '' | + | |
| - | * Indentation with a relative width of 3 characters. | + | |
| - | * Line continuations are aligned with the previous opening delimiter '' | + | |
| - | * All operators are surrounded by exactly one whitespace character, except for arithmetic operators. | + | |
| - | * Removal of extraneous whitespace and consecutive blank lines. | + | |
| - | * Uppercase notation for all Fortran and OpenMP keywords. | + | |
| - | The following formatting decisions are still manual and are never changed by prettify: | + | |
| - | * Positions of line breaks (except for variable declarations and '' | + | |
| - | * No indentation of subsequent '' | + | |
| - | There may be cases where manual alignment is preferred over the rules stated above. The following options for manual formatting are provided: | + | |
| - | * No automatic realignment of line continuations that are prefixed with an ''&'' | + | |
| - | * No auto-formatting of lines to which a comment starting with '' | + | |
| - | * No auto-formatting of code blocks enclosed between two comment lines starting with '' | + | |
| - | A few examples | + | This page has been moved to [[https://manual.cp2k.org/trunk/development/ |
| - | + | ||
| - | * Reduce hanging indent by inserting linebreaks directly after assignment operator and opening delimiter: | + | |
| - | <code fortran> | + | |
| - | ! No: | + | |
| - | long_result_var_name = long_function_name(arg_1, | + | |
| - | arg_3, arg_4, arg_5)+ & | + | |
| - | foo | + | |
| - | ! Yes: | + | |
| - | long_result_var_name = & | + | |
| - | | + | |
| - | arg_1, arg_2, & | + | |
| - | arg_3, arg_4, arg_5)+ & | + | |
| - | foo | + | |
| - | </code> | + | |
| - | * Avoid linebreaks in deeply nested expressions: | + | |
| - | <code fortran> | + | |
| - | ! No: | + | |
| - | bessj0 = (r1+y*(r2+y*(r3+y*(r4+y* & | + | |
| - | (r5+y*r6)))))/(s1+y*(s2+y*(s3+y* & | + | |
| - | | + | |
| - | ! Yes: | + | |
| - | bessj0 = (r1+y*(r2+y*(r3+y*(r4+y*(r5+y*r6)))))/ & | + | |
| - | | + | |
| - | </code> | + | |
| - | * Alignment by explicit bracketing: | + | |
| - | <code fortran> | + | |
| - | ! No: | + | |
| - | foo = bar+foobar(x1, | + | |
| - | foobar(x2, y2, z2)* & | + | |
| - | foobar(x3, y3, z3) | + | |
| - | ! Yes: | + | |
| - | foo = bar+(foobar(x1, | + | |
| - | | + | |
| - | | + | |
| - | </code> | + | |
| - | * Special vertical alignment may require manual formatting: | + | |
| - | <code fortran> | + | |
| - | ! Auto-formatting: | + | |
| - | align_me = [-1, 10, 0, & | + | |
| - | 0, 1000, 0, & | + | |
| - | 0, -1, 1] | + | |
| - | ! Manual alignment (!& disables whitespace formatting): | + | |
| - | align_me = [-1, 10, 0, & !& | + | |
| - | 0, 1000, 0, & !& | + | |
| - | | + | |
| - | ! Alternatively: | + | |
| - | !&< | + | |
| - | align_me = [-1, 10, 0, & | + | |
| - | 0, 1000, 0, & | + | |
| - | | + | |
| - | !&> | + | |
| - | </ | + | |
dev/formattingconventions.1458135034.txt.gz · Last modified: (external edit)
