This manual is deprecated. Please visit https://groupoffice.readthedocs.io for the latest documentation.

Difference between revisions of "Coding guidelines"

From Group-Office Groupware and CRM Documentation
Jump to: navigation, search
(New page: To make sure Group-Office will be developed with a unified coding structure and Graphical user interface the following guidelines have been created. Please follow all of these guidelines a...)
 
Line 2: Line 2:
 
/etc/php.ini
 
/etc/php.ini
  
  1. Always use <?php tags and not <?. Since latest default PHP setups won't accept <? anymore.
+
#Always use <?php tags and not <?. Since latest default PHP setups won't accept <? anymore.
  2. Always code with register_globals=off for the same reason as in point 1.
+
#Always code with register_globals=off for the same reason as in point 1.
  3. Always make sure it will work with magic_quotes_gpc on and off by using the functions smart_stripslashes() and smart_addslashes(). These function work like stripslashes() and addslashes() but check the magic_quotes_gpc setting and thus determine if the operation is needed. So if you want to make sure a variable is escaped by slashes after a POST or GET operation you should use smart_addslashes(); This way it will never escaped twice. If you want to make sure a variable is not escaped then use smart_stripslashes();.
+
#Always make sure it will work with magic_quotes_gpc on and off by using the functions smart_stripslashes() and smart_addslashes(). These function work like stripslashes() and addslashes() but check the magic_quotes_gpc setting and thus determine if the operation is needed. So if you want to make sure a variable is escaped by slashes after a POST or GET operation you should use smart_addslashes(); This way it will never escaped twice. If you want to make sure a variable is not escaped then use smart_stripslashes();.
  4. Turn on notices by setting error_reporting=E_ALL. This is very important because you will find errors easier with this setting enabled and Group-Office might not function properly on systems that do have this enabled and you have not. This also means that you'll have to declare every variable.
+
#Turn on notices by setting error_reporting=E_ALL. This is very important because you will find errors easier with this setting enabled and Group-Office might not function properly on systems that do have this enabled and you have not. This also means that you'll have to declare every variable.
  
 
==Coding structure==
 
==Coding structure==
  
  1. Use single quotes rather then double quotes for consistency in the look of the code.
+
#Use single quotes rather then double quotes for consistency in the look of the code.
  2. Create functions in the following form:
+
#Create functions in the following form:
 
<pre>
 
<pre>
 
       /***
 
       /***
Line 34: Line 34:
 
         return true;
 
         return true;
 
</pre>
 
</pre>
  3. Comment code that is not instantly clear by just reading it.
+
#Comment code that is not instantly clear by just reading it.
  4. Don't double code. Try to re-use every single line of code on other pages. So when something changes there is only place to edit. Group-Office is build up out of classes. These classes perform the database operations and other backend operations.
+
#Don't double code. Try to re-use every single line of code on other pages. So when something changes there is only place to edit. Group-Office is build up out of classes. These classes perform the database operations and other backend operations.
  
 
==Miscellaneous==
 
==Miscellaneous==
  
  1. Group-Office already offers a wide variety of standard functions and classes. Always use these functions and don't reinvent the wheel! The best way to find out what functions are available is to take a look at the files: 'functions.inc', 'classes/base/*.security.class.inc', classes/base/controls/* and Group-Office.php.
+
#Group-Office already offers a wide variety of standard functions and classes. Always use these functions and don't reinvent the wheel! The best way to find out what functions are available is to take a look at the files: 'functions.inc', 'classes/base/*.security.class.inc', classes/base/controls/* and Group-Office.php.
  2. Add a comment block on top with your name and email and version number like this (The two stars are important because PHPDoc doesn't work if you don't put two stars on top):
+
#Add a comment block on top with your name and email and version number like this (The two stars are important because PHPDoc doesn't work if you don't put two stars on top):
 
<pre>
 
<pre>
 
/**  
 
/**  
Line 54: Line 54:
 
  * @author Merijn Schering <mschering@intermesh.nl>
 
  * @author Merijn Schering <mschering@intermesh.nl>
 
  */</pre>
 
  */</pre>
  3. Use a Tab space of 2
+
#Use a Tab space of 2
  4. Keep code 80 characters wide so it's printable.
+
#Keep code 80 characters wide so it's printable.
  5. Never remove code from somebody else. If you do want to replace code then comment it out and put your name and e-mail address in the comment block. This way the original author can review the change and contact you if necessary.
+
#Never remove code from somebody else. If you do want to replace code then comment it out and put your name and e-mail address in the comment block. This way the original author can review the change and contact you if necessary.
  6. Always make use of Group-Office multilingual system. Don hard code language in your code but put them in external language files.
+
#Always make use of Group-Office multilingual system. Don hard code language in your code but put them in external language files.

Revision as of 14:15, 29 September 2008

To make sure Group-Office will be developed with a unified coding structure and Graphical user interface the following guidelines have been created. Please follow all of these guidelines at all times. /etc/php.ini

  1. Always use <?php tags and not <?. Since latest default PHP setups won't accept <? anymore.
  2. Always code with register_globals=off for the same reason as in point 1.
  3. Always make sure it will work with magic_quotes_gpc on and off by using the functions smart_stripslashes() and smart_addslashes(). These function work like stripslashes() and addslashes() but check the magic_quotes_gpc setting and thus determine if the operation is needed. So if you want to make sure a variable is escaped by slashes after a POST or GET operation you should use smart_addslashes(); This way it will never escaped twice. If you want to make sure a variable is not escaped then use smart_stripslashes();.
  4. Turn on notices by setting error_reporting=E_ALL. This is very important because you will find errors easier with this setting enabled and Group-Office might not function properly on systems that do have this enabled and you have not. This also means that you'll have to declare every variable.

Coding structure

  1. Use single quotes rather then double quotes for consistency in the look of the code.
  2. Create functions in the following form:
      /***
      * Short description of the function
      *
      * More detailed multiline description
      *
      * @param string $example_var1 This is the var's desciption
      * @param string $example_var2 This is the var's desciption
      * @access public
      * @return bool Return value description
      */
      function example($example_var1, $example_var2)
      {
        //this is a comment
        if($example_var1)
        {
          $example_var1 = '';
        }else
        {
          $example_var2 = '';
        }
        return true;
  1. Comment code that is not instantly clear by just reading it.
  2. Don't double code. Try to re-use every single line of code on other pages. So when something changes there is only place to edit. Group-Office is build up out of classes. These classes perform the database operations and other backend operations.

Miscellaneous

  1. Group-Office already offers a wide variety of standard functions and classes. Always use these functions and don't reinvent the wheel! The best way to find out what functions are available is to take a look at the files: 'functions.inc', 'classes/base/*.security.class.inc', classes/base/controls/* and Group-Office.php.
  2. Add a comment block on top with your name and email and version number like this (The two stars are important because PHPDoc doesn't work if you don't put two stars on top):
/** 
 * Copyright Intermesh
 * 
 * This file is part of Group-Office. You should have received a copy of the
 * Group-Office license along with Group-Office. See the file /LICENSE.TXT
 * 
 * If you have questions write an e-mail to info@intermesh.nl
 * 
 * @copyright Copyright Intermesh
 * @version $Id: Group-Office.php 2950 2008-09-03 08:39:41Z mschering $
 * @author Merijn Schering <mschering@intermesh.nl>
 */
  1. Use a Tab space of 2
  2. Keep code 80 characters wide so it's printable.
  3. Never remove code from somebody else. If you do want to replace code then comment it out and put your name and e-mail address in the comment block. This way the original author can review the change and contact you if necessary.
  4. Always make use of Group-Office multilingual system. Don hard code language in your code but put them in external language files.