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 [2018/04/03 05:50] (current) – [Coding Guidelines] fix broken link to mailing lists page (#24212) 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:// | + | 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 20: | ||
===== Comments ===== | ===== Comments ===== | ||
- | * Use the ''#'' | + | * Use the ''#'' |
- | * Avoid ''/ | + | * Avoid ''/ |
* Use [[http:// | * Use [[http:// | ||
* Use '' | * Use '' | ||
Line 26: | Line 28: | ||
===== 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 62: | ||
==== 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 77: | ||
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 84: | ||
) { | ) { | ||
... | ... | ||
- | < | + | </code> |
==== Switch statements ==== | ==== Switch statements ==== | ||
+ | |||
+ | Every case //must// have a '' | ||
<code php> | <code php> | ||
Line 95: | Line 98: | ||
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 187: | ||
* $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 201: | ||
</ | </ | ||
+ | ===== 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)