Differences

This shows you the differences between the selected revision and the current version of the page.

punbb13:coding_standards 2010/04/02 08:04 punbb13:coding_standards 2020/02/06 11:04 current
Line 1: Line 1:
-====== Coding standards ======+====== PunBB 1.3 Coding standards ======
Recommendations below describes the appearance of PHP, JavaScript, SQL or any other code used in PunBB and extensions. Recommendations below describes the appearance of PHP, JavaScript, SQL or any other code used in PunBB and extensions.
Line 13: Line 13:
  * Use common sense. If in doubt, look at similar sections in the PunBB source code.   * Use common sense. If in doubt, look at similar sections in the PunBB source code.
-===== Brace policy and indentation ===== +===== Formatting =====
- +
-===== Line breaks =====+
All line breaks should be LF only. Set your editor to save files with UNIX style line breaks. All line breaks should be LF only. Set your editor to save files with UNIX style line breaks.
-===== PHP-specific =====+The indent style and brace policy is the [[http://en.wikipedia.org/wiki/Indent_style#Allman_style_.28bsd_in_Emacs.29|Allman style]]. All indentation should be made with tabs, not spaces. Examples:
-The following rules apply only to PHP.+<code php>if (<expression>) 
 +
 +    <statement>; 
 +    ... 
 +    <statement>; 
 +
 +else 
 +
 +    <statement>; 
 +    ... 
 +    <statement>; 
 +
 + 
 +while (<expression) 
 +
 +    <statement>; 
 +    ... 
 +    <statement>; 
 +
 +</code> 
 + 
 +One allowed exception from the standard Allman style is "braceless" blocks: 
 + 
 +<code php>if (<expression>) 
 +    <statement>; 
 +else 
 +    <statement>; 
 + 
 +while (<expression) 
 +    <statement>; 
 +</code> 
 + 
 +===== PHP =====
  * Use singlequotes as opposed to doublequotes when working with strings. E.g.  ''$str = 'Users: '.$num_users;''  as opposed to ''$str = "Users: $num_users";''  .   * Use singlequotes as opposed to doublequotes when working with strings. E.g.  ''$str = 'Users: '.$num_users;''  as opposed to ''$str = "Users: $num_users";''  .
Line 30: Line 60:
  * Try to avoid PHP warnings/notices in any cases.   * Try to avoid PHP warnings/notices in any cases.
-===== SQL-specific =====+===== SQL =====
-The following rules apply only to SQL. 
  * Always escape potentially harmful data using <code php>$forum_db->escape()</code> Expected integer values should be forced into integer form using ''intval()'' before use in a query.   * Always escape potentially harmful data using <code php>$forum_db->escape()</code> Expected integer values should be forced into integer form using ''intval()'' before use in a query.
  * Prefix tables names and table indexes with <code php>$forum_db->prefix</code>   * Prefix tables names and table indexes with <code php>$forum_db->prefix</code>
  * Use the SQL2003 style [[http://en.wikipedia.org/wiki/Join_(SQL)#Inner_join|explicit join notation]].   * Use the SQL2003 style [[http://en.wikipedia.org/wiki/Join_(SQL)#Inner_join|explicit join notation]].
-  * Whenever possible, write cross-database compatible queries. Developers should take advantage of database helpers like <code php>$forum_db->query_build()</code>. They allows to easily create/extend cross-database compatible queries. In rare cases where database specific queries are needed, every effort should be made to provide alternative queries for other supported databases.+  * Whenever possible, write cross-database compatible queries. Developers should take advantage of [[punbb13:database helpers]]. They allows to easily create/extend cross-database compatible queries. In rare cases where database specific queries are needed, every effort should be made to provide alternative queries for other supported databases. 
 + 
 +===== CSS ===== 
 + 
 +Here is the example of the indentation in CSS files: 
 +<code css>.class { 
 +    attribute: value; 
 +    }</code>

Personal Tools