Documentation

Features

Differences

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

docs:coding_standards 2008/08/23 16:05 docs:coding_standards 2008/08/25 07:14 current
Line 1: Line 1:
====== Coding Standards ====== ====== Coding Standards ======
-This document provides guidelines for code formatting and documentation to individuals and teams contributing to 68 Classifieds+This document provides guidelines for code formatting and documentation to individuals and teams contributing to 68 Classifieds. This is a work in progress and everything listed here is a starting point.  Starting with v4.1 all the core code should adhere to these standards.
-====== PHP File Formatting ======+===== Commenting ===== 
 +In general, code should be commented prolifically. It not only helps describe the flow and intent of the code for less experienced programmers, but can prove invaluable when returning to your own code months down the line. There is not a required format for comments, but the following are recommended. 
 + 
 +DocBlock style comments preceding class and method declarations so they can be picked up by IDEs: 
 + 
 +<code php> 
 +/**  
 +* My Class 
 +*  
 +* @package Example Package 
 +* @subpackage Subpackage  
 +* @category Category  
 +* @author Author Name  
 +* @link http://yoursite.com  
 +*/  
 +class Super_sweet { 
 +</code> 
 + 
 +===== PHP Closing Tag =====
-==== General ==== 
For files that contain only PHP code, the closing tag ("?>") is never permitted. It is not required by PHP, and omitting it prevents the accidental injection of trailing whitespace into the response. For files that contain only PHP code, the closing tag ("?>") is never permitted. It is not required by PHP, and omitting it prevents the accidental injection of trailing whitespace into the response.
-==== Indentation ====+===== Brackets and Indentations =====
-Indentation should consist of 1 tab.+You should indent your code with 1 tab.
-==== Maximum Line Length ====+Opening brackets should start on the next line as the keyword, closing bracket should be aligned below the first letter of the starting keyword. Eg:
-The target line length is 80 characters. That is to say, developers should strive keep each line of their code under 80 characters where possible and practical. However, longer lines are acceptable in some circumstances. The maximum length of any line of PHP code is 120 characters.+<code php> 
 +if ($foo == "bar") 
 +
 +  call_bar(); 
 +
 +elseif($foo == "baz") 
 +
 +  call_baz(); 
 +
 +else 
 +
 +  call_other(); 
 +}
-==== Line Termination ====+</code> 
 + 
 +===== Line Termination =====
Line termination follows the Unix text file convention. Lines must end with a single linefeed (LF) character. Linefeed characters are represented as ordinal 10, or hexadecimal 0x0A. Line termination follows the Unix text file convention. Lines must end with a single linefeed (LF) character. Linefeed characters are represented as ordinal 10, or hexadecimal 0x0A.
Note: Do not use carriage returns (CR) as is the convention in Apple OS's (0x0D) or the carriage return/linefeed combination (CRLF) as is standard for the Windows OS (0x0D, 0x0A). Note: Do not use carriage returns (CR) as is the convention in Apple OS's (0x0D) or the carriage return/linefeed combination (CRLF) as is standard for the Windows OS (0x0D, 0x0A).
 +
 +===== Short Open Tags =====
 +
 +PHP code must always be delimited by the full-form, standard PHP tags:
 +<code php>
 +<?php
 +
 +?>
 +</code>
 +Short tags are never allowed. For files containing only PHP code, the closing tag must always be omitted

Have more questions? Visit our community forums.