mantisbt:coding_guidelines
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| mantisbt:coding_guidelines [2013/08/14 20:00] – Complete review, merge with mantisbt.org/guidelines.php dregad | mantisbt:coding_guidelines [2025/01/11 10:16] (current) – [Coding Guidelines] fallback to PHP-FIG PER Coding Style dregad | ||
|---|---|---|---|
| Line 8: | Line 8: | ||
| The rest of this page describes in which ways we differ, as well as other Mantis-specific guidelines. | The rest of this page describes in which ways we differ, as well as other Mantis-specific guidelines. | ||
| - | Please discuss any omissions or disagreements on the [[http:// | + | If something is not defined in this document, then please apply the rules in PHP-FIG' |
| + | |||
| + | Please discuss any omissions or disagreements on our [[https:// | ||
| ===== General Formatting ===== | ===== General Formatting ===== | ||
| + | * Line length: should generally be kept below **80 chars**, although it is acceptable to have lines up to 120 chars when necessary. | ||
| * Indentations: | * Indentations: | ||
| * PHP tags: always use ''<? | * PHP tags: always use ''<? | ||
| Line 18: | Line 22: | ||
| ===== Comments ===== | ===== Comments ===== | ||
| - | * Use the ''#'' | + | * Use the ''#'' |
| - | * Avoid ''/ | + | * Avoid ''/ |
| * Use [[http:// | * Use [[http:// | ||
| * Use '' | * Use '' | ||
| Line 26: | Line 30: | ||
| ===== Code Blocks ===== | ===== Code Blocks ===== | ||
| - | ==== Braces ==== | + | |
| + | ==== Braces | ||
| * Opening braces '' | * Opening braces '' | ||
| * Closing braces '' | * Closing braces '' | ||
| * At the end of a long condition or many nested conditions you should place end markers such as //# end for loop// or //# end outermost while// | * At the end of a long condition or many nested conditions you should place end markers such as //# end for loop// or //# end outermost while// | ||
| - | |||
| - | ==== Parentheses ==== | ||
| * No space before the opening parentheses '' | * No space before the opening parentheses '' | ||
| * One space after the opening '' | * One space after the opening '' | ||
| + | * Arrays elements should be referenced without spaces, e.g. '' | ||
| - | Example | + | Example:<code php> |
| - | <code php> | + | |
| while( while_condition ) { | while( while_condition ) { | ||
| ... lots of code ... | ... lots of code ... | ||
| Line 61: | Line 64: | ||
| ==== Conditions ==== | ==== Conditions ==== | ||
| - | * For equality comparisons put constants on the left <code php> | + | * For equality comparisons, put constants on the left <code php> |
| if( CONSTANT == $blah ) { | if( CONSTANT == $blah ) { | ||
| ...code... | ...code... | ||
| } | } | ||
| </ | </ | ||
| - | * The NOT operator should be placed right next to its operand, without space, e.g. '' | + | * The NOT operator |
| * Add parentheses as appropriate to make things improve readability (even if not syntactically required by operators precedence). | * Add parentheses as appropriate to make things improve readability (even if not syntactically required by operators precedence). | ||
| Line 76: | Line 79: | ||
| if( $t_cond1 || $t_cond2 ) { | if( $t_cond1 || $t_cond2 ) { | ||
| ... | ... | ||
| - | < | + | </code> |
| - | * Break down the condition over multiple lines <code php> | + | * Break down the condition over multiple lines, aligning and grouping the conditions |
| if( CONSTANT > some_function( arg1, arg2, arg3 ) | if( CONSTANT > some_function( arg1, arg2, arg3 ) | ||
| || 0 <= $var1 | || 0 <= $var1 | ||
| Line 83: | Line 86: | ||
| ) { | ) { | ||
| ... | ... | ||
| - | < | + | </code> |
| ==== Switch statements ==== | ==== Switch statements ==== | ||
| + | |||
| + | Every case //must// have a '' | ||
| <code php> | <code php> | ||
| Line 95: | Line 100: | ||
| case 2: | case 2: | ||
| blah; | blah; | ||
| - | # Fall through | + | # Fall through |
| - | case 3: | + | case 3: # No need for a break here |
| case 4: | case 4: | ||
| blah; | blah; | ||
| - | | + | |
| default: | default: | ||
| blah; | blah; | ||
| } | } | ||
| - | < | + | </code> |
| Line 184: | Line 189: | ||
| * $t_result follows the same pattern as $t_query. | * $t_result follows the same pattern as $t_query. | ||
| * $t_row also follows the same pattern as $t_query. | * $t_row also follows the same pattern as $t_query. | ||
| + | |||
| Line 197: | Line 203: | ||
| </ | </ | ||
| + | ===== CSS ===== | ||
| + | |||
| + | Tables should be wrapped a '' | ||
| + | |||
| + | <code html> | ||
| + | <div class=" | ||
| + | </ | ||
mantisbt/coding_guidelines.1376524857.txt.gz · Last modified: 2013/08/14 20:08 (external edit)
