mirror of
https://github.com/EGroupware/egroupware.git
synced 2025-08-10 16:57:54 +02:00
Updated Coding Standards (mediawiki => markdown)
@ -1,4 +1,4 @@
|
|||||||
== Coding Standards ==
|
##Coding Standards
|
||||||
* Format your code so that we can read it, please!
|
* Format your code so that we can read it, please!
|
||||||
|
|
||||||
* Use tabs for formatting, NOT SPACES. Tabs create smaller files and editors allow developers to view a tab as however many spaces as they prefer. Spaces do not allow this. There is one exception (see arrays below).
|
* Use tabs for formatting, NOT SPACES. Tabs create smaller files and editors allow developers to view a tab as however many spaces as they prefer. Spaces do not allow this. There is one exception (see arrays below).
|
||||||
@ -10,39 +10,41 @@
|
|||||||
* Comments go on the line ABOVE the code, NOT to the right of the code!
|
* Comments go on the line ABOVE the code, NOT to the right of the code!
|
||||||
|
|
||||||
* For each section of code put a section divider with basic explanation of the following code/functions. It should look like this:
|
* For each section of code put a section divider with basic explanation of the following code/functions. It should look like this:
|
||||||
|
```php
|
||||||
/**
|
/**
|
||||||
* These functions are used to pick my nose
|
* These functions are used to pick my nose
|
||||||
*/
|
*/
|
||||||
|
```
|
||||||
* Do not document every bit of code in comments. PHP is an interpreted language and it will be nasty on performance.
|
* Do not document every bit of code in comments. PHP is an interpreted language and it will be nasty on performance.
|
||||||
|
|
||||||
* Use switch statements where many elseif's are going to be used. Switch is faster and I like it better!
|
* Use switch statements where many elseif's are going to be used. Switch is faster and I like it better!
|
||||||
|
|
||||||
* <b>If - statements</b> need to use the following format:
|
* <b>If - statements</b> need to use the following format:
|
||||||
if ($var == "example")
|
```php
|
||||||
{
|
if ($var == "example")
|
||||||
echo "This is only an example";
|
{
|
||||||
}
|
echo "This is only an example";
|
||||||
else
|
}
|
||||||
{
|
else
|
||||||
echo "This is not a test. This is the real thing";
|
{
|
||||||
}
|
echo "This is not a test. This is the real thing";
|
||||||
//Do NOT make if statements like this:
|
}
|
||||||
if ($var == 'example'){ echo 'An example'; }
|
//Do NOT make if statements like this:
|
||||||
|
if ($var == 'example'){ echo 'An example'; }
|
||||||
|
```
|
||||||
<b>All other styles are not to be used.</b>
|
<b>All other styles are not to be used.</b>
|
||||||
|
|
||||||
* ALL 'if' statements MUST have matching { } (brackets). Do NOT create 'if' statements like this:
|
* ALL 'if' statements MUST have matching { } (brackets). Do NOT create 'if' statements like this:
|
||||||
if ($a == b)
|
```php
|
||||||
dosomething();
|
if ($a == b)
|
||||||
//or:
|
dosomething();
|
||||||
if ($a == b) dosomething();
|
//or:
|
||||||
|
if ($a == b) dosomething();
|
||||||
|
```
|
||||||
<b>They make the code more difficult to read and follow.</b>
|
<b>They make the code more difficult to read and follow.</b>
|
||||||
|
|
||||||
* class/function format:
|
* class/function format:
|
||||||
<code>
|
```php
|
||||||
class testing
|
class testing
|
||||||
{
|
{
|
||||||
function print_to_screen()
|
function print_to_screen()
|
||||||
@ -59,23 +61,23 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</code>
|
```
|
||||||
|
|
||||||
* Associative arrays must be written in the following manner:
|
* Associative arrays must be written in the following manner:
|
||||||
<code>
|
```php
|
||||||
$array = array
|
$array = array
|
||||||
(
|
(
|
||||||
'var' => 'value',
|
'var' => 'value',
|
||||||
'var2' => 'value2'
|
'var2' => 'value2'
|
||||||
);
|
);
|
||||||
</code>
|
```
|
||||||
|
|
||||||
** Note that tabs are preferred around the '=>'.
|
<b>Note that tabs are preferred around the '=>'.</b>
|
||||||
|
|
||||||
* Use the long format for <?php. Do NOT use <?.
|
* Use the long format for <?php. Do NOT use <?.
|
||||||
|
|
||||||
* All code should start with 1 tab. Example:
|
* All code should start with 1 tab. Example:
|
||||||
<code>
|
```php
|
||||||
<?php
|
<?php
|
||||||
dosomething();
|
dosomething();
|
||||||
if ($a)
|
if ($a)
|
||||||
@ -91,15 +93,5 @@ if ($a)
|
|||||||
{
|
{
|
||||||
dosomemorestuff();
|
dosomemorestuff();
|
||||||
}
|
}
|
||||||
</code>
|
```
|
||||||
* Use lower case for variable and function names. No stubbly-case (mixed-case) code.
|
|
||||||
<code>
|
|
||||||
//correct
|
|
||||||
var $my_var;
|
|
||||||
function my_function()
|
|
||||||
//incorrect
|
|
||||||
var $MyVar;
|
|
||||||
function MyFunction()
|
|
||||||
</code>
|
|
||||||
|
|
||||||
Thanks for following these rules :)
|
Thanks for following these rules :)
|
Reference in New Issue
Block a user