coding
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
coding [2007/12/22 14:30] – external edit 127.0.0.1 | coding [2020/11/23 17:23] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 3: | Line 3: | ||
* OSInet contributions to Drupal | * OSInet contributions to Drupal | ||
* Contributions to Drupal core follow the [[http:// | * Contributions to Drupal core follow the [[http:// | ||
+ | * Contributions to non-OSInet contributed code follow the coding convention of said code, usually the same Drupal coding standard as core. | ||
* Contributions outside core follow the here-defined OSInet coding style. | * Contributions outside core follow the here-defined OSInet coding style. | ||
* Contributions to PEAR follow the [[http:// | * Contributions to PEAR follow the [[http:// | ||
Line 11: | Line 12: | ||
Examples on this page are given in the context of a module (Drupal) or class called G2. | Examples on this page are given in the context of a module (Drupal) or class called G2. | ||
- | All code must work under error_reporting(E_ALL | E_STRICT); | + | All code must work under error_reporting(E_ALL | E_STRICT) |
====== Indenting ====== | ====== Indenting ====== | ||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
Line 33: | Line 45: | ||
< | < | ||
</tr> | </tr> | ||
- | <tr style=" | + | <tr style=" |
- | | + | |
{ | { | ||
$ret = action; | $ret = action; | ||
return $ret; | return $ret; | ||
- | }</ | + | }</ |
- | | + | |
return action; | return action; | ||
- | }</ | + | }</ |
- | | + | |
{ | { | ||
return action; | return action; | ||
Line 64: | Line 73: | ||
</ | </ | ||
- | ===== Class Declarations ===== | ||
+ | |||
+ | |||
+ | ===== Class Declarations ===== | ||
< | < | ||
Line 75: | Line 86: | ||
< | < | ||
</tr> | </tr> | ||
- | <tr style=" | + | <tr style=" |
- | | + | |
{ | { | ||
// members | // members | ||
- | }</ | + | }</ |
- | | + | |
- | | + | |
- | | + | |
{ | { | ||
// members | // members | ||
Line 101: | Line 108: | ||
< | < | ||
</tr> | </tr> | ||
- | <tr style=" | + | <tr style=" |
- | | + | |
{ | { | ||
action1; | action1; | ||
Line 113: | Line 119: | ||
{ | { | ||
defaultaction; | defaultaction; | ||
- | }</ | + | }</ |
- | | + | |
action1; | action1; | ||
} | } | ||
Line 122: | Line 127: | ||
else { | else { | ||
defaultaction; | defaultaction; | ||
- | }</ | + | }</ |
- | | + | |
action1; | action1; | ||
} elseif ((test3) && (test4)) { | } elseif ((test3) && (test4)) { | ||
Line 129: | Line 133: | ||
} else { | } else { | ||
defaultaction; | defaultaction; | ||
- | }</ | + | }</ |
- | | + | |
action1; | action1; | ||
} else if (test3) { | } else if (test3) { | ||
Line 136: | Line 139: | ||
} else { | } else { | ||
| | ||
- | }</ | + | }</ |
- | | + | |
<tr> | <tr> | ||
< | < | ||
Line 149: | Line 151: | ||
For OSInet, long tests must be wrapped to align readably. Although ZF does not mention this, the line length requirement makes it likely too. | For OSInet, long tests must be wrapped to align readably. Although ZF does not mention this, the line length requirement makes it likely too. | ||
+ | |||
===== switch ===== | ===== switch ===== | ||
Line 160: | Line 163: | ||
< | < | ||
</tr> | </tr> | ||
- | <tr style=" | + | <tr style=" |
- | | + | |
{ | { | ||
case 1: | case 1: | ||
Line 174: | Line 176: | ||
defaultaction; | defaultaction; | ||
break; | break; | ||
- | }</ | + | }</ |
- | | + | |
case 1: | case 1: | ||
action1; | action1; | ||
Line 187: | Line 188: | ||
defaultaction; | defaultaction; | ||
break; | break; | ||
- | }</ | + | }</ |
- | | + | |
case 1: | case 1: | ||
action1; | action1; | ||
Line 200: | Line 200: | ||
defaultaction; | defaultaction; | ||
break; | break; | ||
- | }</ | + | }</ |
- | | + | |
case 1: | case 1: | ||
break; | break; | ||
Line 210: | Line 209: | ||
default: | default: | ||
break; | break; | ||
- | }</ | + | }</ |
- | | + | |
</ | </ | ||
</ | </ | ||
+ | |||
===== General table ===== | ===== General table ===== | ||
Line 224: | Line 223: | ||
^ ... control, closing | = ZF | n.a. || The closing brace is always written on its own line. | | ^ ... control, closing | = ZF | n.a. || The closing brace is always written on its own line. | | ||
^ ... classes | = ZF | n.a. || The brace is always written on the line underneath the class name. | | ^ ... classes | = ZF | n.a. || The brace is always written on the line underneath the class name. | | ||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
Line 243: | Line 247: | ||
Spacing, one-liner: **identical** | Spacing, one-liner: **identical** | ||
- | |||
Spacing, indented: **Different** | Spacing, indented: **Different** | ||
Line 261: | Line 264: | ||
Additional comma: identical. | Additional comma: identical. | ||
+ | ====== Including Code ====== | ||
- | |||
- | ====== Including Code ====== | ||
OSInet contrib code does not support PHP4, so PHP5 structures like the new object model are standard. | OSInet contrib code does not support PHP4, so PHP5 structures like the new object model are standard. | ||
+ | |||
+ | |||
This means that including can make use of the autoload mechanism, which can be more efficient under caching than using require_once with conditional content. | This means that including can make use of the autoload mechanism, which can be more efficient under caching than using require_once with conditional content. | ||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
Line 290: | Line 304: | ||
The rule regarding the closing ?> tag is only applicable to " | The rule regarding the closing ?> tag is only applicable to " | ||
- | |||
- | |||
- | |||
- | |||
Line 380: | Line 390: | ||
====== Using CVS ====== | ====== Using CVS ====== | ||
+ | |||
+ | |||
**Identical** | **Identical** | ||
+ | |||
+ | |||
Additional rule: modules must define a constant containing the version information to be displayed on the module settings page. See the rules for constants below. | Additional rule: modules must define a constant containing the version information to be displayed on the module settings page. See the rules for constants below. | ||
+ | |||
+ | |||
====== Example URLs ====== | ====== Example URLs ====== | ||
+ | |||
+ | |||
**Identical** | **Identical** | ||
+ | |||
+ | |||
+ | |||
====== Naming Conventions ====== | ====== Naming Conventions ====== | ||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
Line 401: | Line 434: | ||
===== General ===== | ===== General ===== | ||
+ | |||
< | < | ||
<table class=" | <table class=" | ||
Line 413: | Line 447: | ||
<tr style=" | <tr style=" | ||
< | < | ||
- | < | + | <td>as ZF</td> |
<td style=" | <td style=" | ||
<td style=" | <td style=" | ||
Line 530: | Line 564: | ||
</ | </ | ||
</ | </ | ||
- | |||
- | |||
===== Variables ===== | ===== Variables ===== | ||
- | Variables naming following the rules for functions and methods. | + | Variables naming following the rules for functions and methods. Exceptions: |
- | + | ||
- | Exceptions: | + | |
* existing libraries or APIs are not renamed. Facade APIs may be used until existing libraries match the new format | * existing libraries or APIs are not renamed. Facade APIs may be used until existing libraries match the new format | ||
Line 561: | Line 591: | ||
* functions or methods returning unsafe values are prefixed by " | * functions or methods returning unsafe values are prefixed by " | ||
* " | * " | ||
- | |||
- | |||
- | |||
- | |||
Line 577: | Line 603: | ||
This style of coding is now considered obsolete (even under Drupal conventions, | This style of coding is now considered obsolete (even under Drupal conventions, | ||
+ | |||
<code php> | <code php> | ||
class G2 | class G2 | ||
Line 584: | Line 611: | ||
} | } | ||
</ | </ | ||
+ | |||
===== Drupal-specific: | ===== Drupal-specific: | ||
Line 608: | Line 636: | ||
My_Module:: | My_Module:: | ||
</ | </ | ||
- |
coding.txt · Last modified: 2020/11/23 17:23 by 127.0.0.1